From: tedu Date: Wed, 16 Apr 2014 19:36:19 +0000 (+0000) Subject: lots of ifdef cleanup X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b176958eb5be107317be8e1ea607245a3d15055a;p=openbsd lots of ifdef cleanup --- diff --git a/lib/libssl/src/apps/apps.c b/lib/libssl/src/apps/apps.c index a97d779f53d..e92e95b332c 100644 --- a/lib/libssl/src/apps/apps.c +++ b/lib/libssl/src/apps/apps.c @@ -112,9 +112,7 @@ #include #include #include -#if !defined(OPENSSL_SYSNAME_WIN32) && !defined(NETWARE_CLIB) #include -#endif #include #include #include @@ -133,18 +131,11 @@ #include #endif #include -#ifndef OPENSSL_NO_JPAKE -#include -#endif #define NON_MAIN #include "apps.h" #undef NON_MAIN -#ifdef _WIN32 -static int WIN32_rename(const char *from, const char *to); -#define rename(from,to) WIN32_rename((from),(to)) -#endif typedef struct { const char *name; @@ -164,98 +155,6 @@ static EVP_PKEY *load_netscape_key(BIO *err, BIO *key, const char *file, #endif int app_init(long mesgwin); -#ifdef undef /* never finished - probably never will be :-) */ -int -args_from_file(char *file, int *argc, char **argv[]) -{ - FILE *fp; - int num, i; - unsigned int len; - static char *buf = NULL; - static char **arg = NULL; - char *p; - - fp = fopen(file, "r"); - if (fp == NULL) - return (0); - - if (fseek(fp, 0, SEEK_END) == 0) - len = ftell(fp), rewind(fp); - else - len = -1; - if (len <= 0) { - fclose(fp); - return (0); - } - - *argc = 0; - *argv = NULL; - - if (buf != NULL) - OPENSSL_free(buf); - buf = (char *)OPENSSL_malloc(len + 1); - if (buf == NULL) - return (0); - - len = fread(buf, 1, len, fp); - if (len <= 1) - return (0); - buf[len] = '\0'; - - i = 0; - for (p = buf; *p; p++) - if (*p == '\n') - i++; - if (arg != NULL) - OPENSSL_free(arg); - arg = (char **)OPENSSL_malloc(sizeof(char *)*(i*2)); - - *argv = arg; - num = 0; - p = buf; - for (;;) { - if (!*p) - break; - if (*p == '#') /* comment line */ - { - while (*p && (*p != '\n')) - p++; - continue; - } - /* else we have a line */ - *(arg++) = p; - num++; - while (*p && ((*p != ' ') && (*p != '\t') && (*p != '\n'))) - p++; - if (!*p) - break; - if (*p == '\n') { - *(p++) = '\0'; - continue; - } - /* else it is a tab or space */ - p++; - while (*p && ((*p == ' ') || (*p == '\t') || (*p == '\n'))) - p++; - if (!*p) - break; - if (*p == '\n') { - p++; - continue; - } - *(arg++) = p++; - num++; - while (*p && (*p != '\n')) - p++; - if (!*p) - break; - /* else *p == '\n' */ - *(p++) = '\0'; - } - *argc = num; - return (1); -} -#endif int str2fmt(char *s) @@ -287,44 +186,6 @@ str2fmt(char *s) return (FORMAT_UNDEF); } -#if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_NETWARE) -void -program_name(char *in, char *out, int size) -{ - int i, n; - char *p = NULL; - - n = strlen(in); - /* find the last '/', '\' or ':' */ - for (i = n - 1; i > 0; i--) { - if ((in[i] == '/') || (in[i] == '\\') || (in[i] == ':')) { - p = &(in[i + 1]); - break; - } - } - if (p == NULL) - p = in; - n = strlen(p); - - /* strip off trailing .exe if present. */ - if ((n > 4) && (p[n - 4] == '.') && - ((p[n - 3] == 'e') || (p[n - 3] == 'E')) && - ((p[n - 2] == 'x') || (p[n - 2] == 'X')) && - ((p[n - 1] == 'e') || (p[n - 1] == 'E'))) - n -= 4; - - if (n > size - 1) - n = size - 1; - - for (i = 0; i < n; i++) { - if ((p[i] >= 'A') && (p[i] <= 'Z')) - out[i] = p[i] - 'A' + 'a'; - else - out[i] = p[i]; - } - out[n] = '\0'; -} -#else void program_name(char *in, char *out, int size) { @@ -337,7 +198,6 @@ program_name(char *in, char *out, int size) p = in; BUF_strlcpy(out, p, size); } -#endif int chopup_args(ARGS *arg, char *buf, int *argc, char **argv[]) @@ -635,7 +495,6 @@ app_get_pass(BIO *err, char *arg, int keepbio) BIO_printf(err, "Can't open file %s\n", arg + 5); return NULL; } -#if !defined(_WIN32) /* * Under _WIN32, which covers even Win64 and CE, file * descriptors referenced by BIO_s_fd are not inherited @@ -656,7 +515,6 @@ app_get_pass(BIO *err, char *arg, int keepbio) /* Can't do BIO_gets on an fd BIO so add a buffering BIO */ btmp = BIO_new(BIO_f_buffer()); pwdbio = BIO_push(btmp, pwdbio); -#endif } else if (!strcmp(arg, "stdin")) { pwdbio = BIO_new_fp(stdin, BIO_NOCLOSE); if (!pwdbio) { @@ -2603,193 +2461,9 @@ next_protos_parse(unsigned short *outlen, const char *in) /* * Platform-specific sections */ -#if defined(_WIN32) -# ifdef fileno -# undef fileno -# define fileno(a) (int)_fileno(a) -# endif - -# include -# include - -static int -WIN32_rename(const char *from, const char *to) -{ - TCHAR *tfrom = NULL, *tto; - DWORD err; - int ret = 0; - - if (sizeof(TCHAR) == 1) { - tfrom = (TCHAR *)from; - tto = (TCHAR *)to; - } - else /* UNICODE path */ - { - size_t i, flen = strlen(from) + 1, tlen = strlen(to) + 1; - tfrom = (TCHAR *)malloc(sizeof(TCHAR)*(flen + tlen)); - if (tfrom == NULL) - goto err; - tto = tfrom + flen; -#if !defined(_WIN32_WCE) || _WIN32_WCE>=101 - if (!MultiByteToWideChar(CP_ACP, 0, from, flen, (WCHAR *)tfrom, flen)) -#endif - for (i = 0;i < flen;i++) tfrom[i] = (TCHAR)from[i]; -#if !defined(_WIN32_WCE) || _WIN32_WCE>=101 - if (!MultiByteToWideChar(CP_ACP, 0, to, tlen, (WCHAR *)tto, tlen)) -#endif - for (i = 0;i < tlen;i++) tto[i] = (TCHAR)to[i]; - } - - if (MoveFile(tfrom, tto)) - goto ok; - err = GetLastError(); - if (err == ERROR_ALREADY_EXISTS || err == ERROR_FILE_EXISTS) { - if (DeleteFile(tto) && MoveFile(tfrom, tto)) - goto ok; - err = GetLastError(); - } - if (err == ERROR_FILE_NOT_FOUND || err == ERROR_PATH_NOT_FOUND) - errno = ENOENT; - else if (err == ERROR_ACCESS_DENIED) - errno = EACCES; - else - errno = EINVAL; /* we could map more codes... */ -err: - ret = -1; -ok: - if (tfrom != NULL && tfrom != (TCHAR *)from) - free(tfrom); - return ret; -} -#endif /* app_tminterval section */ -#if defined(_WIN32) -double -app_tminterval(int stop, int usertime) -{ - FILETIME now; - double ret = 0; - static ULARGE_INTEGER tmstart; - static int warning = 1; -#ifdef _WIN32_WINNT - static HANDLE proc = NULL; - - if (proc == NULL) { - if (check_winnt()) - proc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, - GetCurrentProcessId()); - if (proc == NULL) - proc = (HANDLE) - 1; - } - - if (usertime && proc != (HANDLE) - 1) { - FILETIME junk; - GetProcessTimes(proc, &junk, &junk, &junk, &now); - } else -#endif - { - SYSTEMTIME systime; - - if (usertime && warning) { - BIO_printf(bio_err, "To get meaningful results, run " - "this program on idle system.\n"); - warning = 0; - } - GetSystemTime(&systime); - SystemTimeToFileTime(&systime, &now); - } - - if (stop == TM_START) { - tmstart.u.LowPart = now.dwLowDateTime; - tmstart.u.HighPart = now.dwHighDateTime; - } else { - ULARGE_INTEGER tmstop; - - tmstop.u.LowPart = now.dwLowDateTime; - tmstop.u.HighPart = now.dwHighDateTime; - - ret = (__int64)(tmstop.QuadPart - tmstart.QuadPart)*1e - 7; - } - - return (ret); -} - -#elif defined(OPENSSL_SYSTEM_VXWORKS) -#include - -double -app_tminterval(int stop, int usertime) -{ - double ret = 0; -#ifdef CLOCK_REALTIME - static struct timespec tmstart; - struct timespec now; -#else - static unsigned long tmstart; - unsigned long now; -#endif - static int warning = 1; - - if (usertime && warning) { - BIO_printf(bio_err, "To get meaningful results, run " - "this program on idle system.\n"); - warning = 0; - } - -#ifdef CLOCK_REALTIME - clock_gettime(CLOCK_REALTIME, &now); - if (stop == TM_START) - tmstart = now; - else ret = ( (now.tv_sec + now.tv_nsec*1e - 9) - - (tmstart.tv_sec + tmstart.tv_nsec*1e - 9) ); -#else - now = tickGet(); - if (stop == TM_START) - tmstart = now; - else - ret = (now - tmstart)/(double)sysClkRateGet(); -#endif - return (ret); -} - -#elif defined(OPENSSL_SYSTEM_VMS) -#include -#include - -double -app_tminterval(int stop, int usertime) -{ - static clock_t tmstart; - double ret = 0; - clock_t now; -#ifdef __TMS - struct tms rus; - - now = times(&rus); - if (usertime) - now = rus.tms_utime; -#else - if (usertime) - now = clock(); /* sum of user and kernel times */ - else { - struct timeval tv; - gettimeofday(&tv, NULL); - now = (clock_t)( - (unsigned long long)tv.tv_sec*CLK_TCK + - (unsigned long long)tv.tv_usec*(1000000/CLK_TCK) - ); - } -#endif - if (stop == TM_START) - tmstart = now; - else - ret = (now - tmstart)/(double)(CLK_TCK); - - return (ret); -} - -#elif defined(_SC_CLK_TCK) /* by means of unistd.h */ +#if defined(_SC_CLK_TCK) /* by means of unistd.h */ #include double @@ -2841,34 +2515,6 @@ app_tminterval(int stop, int usertime) #endif /* app_isdir section */ -#ifdef _WIN32 -int -app_isdir(const char *name) -{ - HANDLE hList; - WIN32_FIND_DATA FileData; -#if defined(UNICODE) || defined(_UNICODE) - size_t i, len_0 = strlen(name) + 1; - - if (len_0 > sizeof(FileData.cFileName)/sizeof(FileData.cFileName[0])) - return -1; - -#if !defined(_WIN32_WCE) || _WIN32_WCE>=101 - if (!MultiByteToWideChar(CP_ACP, 0, name, len_0, FileData.cFileName, len_0)) -#endif - for (i = 0; i < len_0; i++) - FileData.cFileName[i] = (WCHAR)name[i]; - - hList = FindFirstFile(FileData.cFileName, &FileData); -#else - hList = FindFirstFile(name, &FileData); -#endif - if (hList == INVALID_HANDLE_VALUE) - return -1; - FindClose(hList); - return ((FileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) != 0); -} -#else #include #ifndef S_ISDIR # if defined(_S_IFMT) && defined(_S_IFDIR) @@ -2892,7 +2538,6 @@ app_isdir(const char *name) return -1; #endif } -#endif /* raw_read|write section */ #if defined(_WIN32) && defined(STD_INPUT_HANDLE) diff --git a/lib/libssl/src/apps/ca.c b/lib/libssl/src/apps/ca.c index 54344a13770..7a68552c62e 100644 --- a/lib/libssl/src/apps/ca.c +++ b/lib/libssl/src/apps/ca.c @@ -783,11 +783,7 @@ bad: that to access(). However, time's too short to do that just now. */ -#ifndef _WIN32 if (access(outdir, R_OK|W_OK|X_OK) != 0) -#else - if (_access(outdir, R_OK|W_OK|X_OK) != 0) -#endif { BIO_printf(bio_err, "I am unable to access the %s directory\n", outdir); perror(outdir); diff --git a/lib/libssl/src/apps/speed.c b/lib/libssl/src/apps/speed.c index 7e60c08a00d..fb4f25ed418 100644 --- a/lib/libssl/src/apps/speed.c +++ b/lib/libssl/src/apps/speed.c @@ -288,49 +288,11 @@ static SIGRETTYPE sig_done(int sig) #define START 0 #define STOP 1 -#if defined(_WIN32) - -#if !defined(SIGALRM) -# define SIGALRM -#endif -static unsigned int lapse,schlock; -static void alarm_win32(unsigned int secs) { lapse = secs*1000; } -#define alarm alarm_win32 - -static DWORD WINAPI sleepy(VOID *arg) - { - schlock = 1; - Sleep(lapse); - run = 0; - return 0; - } - -static double Time_F(int s) - { - if (s == START) - { - HANDLE thr; - schlock = 0; - thr = CreateThread(NULL,4096,sleepy,NULL,0,NULL); - if (thr==NULL) - { - DWORD ret=GetLastError(); - BIO_printf(bio_err,"unable to CreateThread (%d)",ret); - ExitProcess(ret); - } - CloseHandle(thr); /* detach the thread */ - while (!schlock) Sleep(0); /* scheduler spinlock */ - } - - return app_tminterval(s,usertime); - } -#else static double Time_F(int s) { return app_tminterval(s,usertime); } -#endif #ifndef OPENSSL_NO_ECDH @@ -1486,9 +1448,7 @@ int MAIN(int argc, char **argv) #else #define COND(c) (run && count<0x7fffffff) #define COUNT(d) (count) -#ifndef _WIN32 signal(SIGALRM,sig_done); -#endif #endif /* SIGALRM */ #ifndef OPENSSL_NO_MD2