diff options
Diffstat (limited to 'tests/server/util.c')
-rw-r--r-- | tests/server/util.c | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/tests/server/util.c b/tests/server/util.c index 52802a82..06f3ce10 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -19,20 +19,11 @@ * KIND, either express or implied. * ***************************************************************************/ - -#define CURL_NO_OLDIES - -#include "setup.h" /* portability help from the lib directory */ +#include "server_setup.h" #ifdef HAVE_SIGNAL_H #include <signal.h> #endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_SYS_SOCKET_H -#include <sys/socket.h> -#endif #ifdef HAVE_NETINET_IN_H #include <netinet/in.h> #endif @@ -57,10 +48,44 @@ #include "util.h" #include "timeval.h" +#ifdef USE_WINSOCK +#undef EINTR +#define EINTR 4 /* errno.h value */ +#undef EINVAL +#define EINVAL 22 /* errno.h value */ +#endif + #if defined(ENABLE_IPV6) && defined(__MINGW32__) const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }}; #endif +/* This function returns a pointer to STATIC memory. It converts the given + * binary lump to a hex formatted string usable for output in logs or + * whatever. + */ +char *data_to_hex(char *data, size_t len) +{ + static char buf[256*3]; + size_t i; + char *optr = buf; + char *iptr = data; + + if(len > 255) + len = 255; + + for(i=0; i < len; i++) { + if((data[i] >= 0x20) && (data[i] < 0x7f)) + *optr++ = *iptr++; + else { + sprintf(optr, "%%%02x", *iptr++); + optr+=3; + } + } + *optr=0; /* in case no sprintf() was used */ + + return buf; +} + void logmsg(const char *msg, ...) { va_list ap; @@ -100,7 +125,7 @@ void logmsg(const char *msg, ...) fclose(logfp); } else { - error = ERRNO; + error = errno; fprintf(stderr, "fopen() failed with error: %d %s\n", error, strerror(error)); fprintf(stderr, "Error opening file: %s\n", serverlogfile); @@ -190,7 +215,7 @@ int wait_ms(int timeout_ms) if(!timeout_ms) return 0; if(timeout_ms < 0) { - SET_SOCKERRNO(EINVAL); + errno = EINVAL; return -1; } #if defined(MSDOS) @@ -210,7 +235,7 @@ int wait_ms(int timeout_ms) #endif /* HAVE_POLL_FINE */ if(r != -1) break; - error = SOCKERRNO; + error = errno; if(error && (error != EINTR)) break; pending_ms = timeout_ms - (int)curlx_tvdiff(curlx_tvnow(), initial_tv); @@ -231,7 +256,7 @@ int write_pidfile(const char *filename) pid = (long)getpid(); pidfile = fopen(filename, "wb"); if(!pidfile) { - logmsg("Couldn't write pid file: %s %s", filename, strerror(ERRNO)); + logmsg("Couldn't write pid file: %s %s", filename, strerror(errno)); return 0; /* fail */ } fprintf(pidfile, "%ld\n", pid); @@ -248,7 +273,7 @@ void set_advisor_read_lock(const char *filename) do { lockfile = fopen(filename, "wb"); - } while((lockfile == NULL) && ((error = ERRNO) == EINTR)); + } while((lockfile == NULL) && ((error = errno) == EINTR)); if(lockfile == NULL) { logmsg("Error creating lock file %s error: %d %s", filename, error, strerror(error)); @@ -257,7 +282,7 @@ void set_advisor_read_lock(const char *filename) do { res = fclose(lockfile); - } while(res && ((error = ERRNO) == EINTR)); + } while(res && ((error = errno) == EINTR)); if(res) logmsg("Error closing lock file %s error: %d %s", filename, error, strerror(error)); @@ -276,7 +301,7 @@ void clear_advisor_read_lock(const char *filename) do { res = unlink(filename); - } while(res && ((error = ERRNO) == EINTR)); + } while(res && ((error = errno) == EINTR)); if(res) logmsg("Error removing lock file %s error: %d %s", filename, error, strerror(error)); |