18
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
* KIND, either express or implied.
21
* $Id: util.c,v 1.3 2005/05/01 12:56:09 bagder Exp $
21
* $Id: util.c,v 1.6 2005/09/15 20:22:43 bagder Exp $
22
22
***************************************************************************/
23
23
#include "setup.h" /* portability help from the lib directory */
82
82
localtime(&tv.tv_sec); /* not multithread safe but we don't care */
85
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%02ld",
86
now->tm_hour, now->tm_min, now->tm_sec,
85
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
86
now->tm_hour, now->tm_min, now->tm_sec, tv.tv_usec);
90
89
vsprintf(buffer, msg, ap);
93
92
logfp = fopen(serverlogfile, "a");
94
fprintf(logfp?logfp:stderr, /* write to stderr if the logfile doesn't open */
95
"%s %s\n", timebuf, buffer);
94
fprintf(logfp, "%s %s\n", timebuf, buffer);
99
#if defined(WIN32) && !defined(__CYGWIN__)
100
/* use instead of perror() on generic windows */
101
void win32_perror (const char *msg)
104
DWORD err = WSAGetLastError();
106
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
107
LANG_NEUTRAL, buf, sizeof(buf), NULL))
108
snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
110
fprintf(stderr, "%s: ", msg);
111
fprintf(stderr, "%s\n", buf);
115
#if defined(WIN32) && !defined(__CYGWIN__)
116
void win32_init(void)
118
WORD wVersionRequested;
121
wVersionRequested = MAKEWORD(2, 0);
123
err = WSAStartup(wVersionRequested, &wsaData);
126
perror("Winsock init failed");
127
logmsg("Error initialising winsock -- aborting\n");
131
if ( LOBYTE( wsaData.wVersion ) != 2 ||
132
HIBYTE( wsaData.wVersion ) != 0 ) {
135
perror("Winsock init failed");
136
logmsg("No suitable winsock.dll found -- aborting\n");
141
void win32_cleanup(void)
147
/* set by the main code to point to where the test dir is */
148
const char *path=".";
150
char *test2file(long testno)
152
static char filename[256];
153
snprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno);