27 #ifdef HAVE_NETINET_IN_H 28 #include <netinet/in.h> 30 #ifdef _XOPEN_SOURCE_EXTENDED 32 #include <arpa/inet.h> 39 #elif defined(HAVE_SYS_POLL_H) 46 #define ENABLE_CURLX_PRINTF 63 #if defined(ENABLE_IPV6) && defined(__MINGW32__) 64 #if (__W32API_MAJOR_VERSION < 3) || \ 65 ((__W32API_MAJOR_VERSION == 3) && (__W32API_MINOR_VERSION < 6)) 66 const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }};
76 static char buf[256*3];
84 for(i = 0; i <
len; i++) {
85 if((data[i] >= 0x20) && (data[i] < 0x7f))
88 snprintf(optr, 4,
"%%%02x", *iptr++);
111 fprintf(stderr,
"Error: serverlogfile not set\n");
117 epoch_offset = time(NULL) - tv.
tv_sec;
120 sec = epoch_offset + tv.
tv_sec;
121 now = localtime(&sec);
123 snprintf(timebuf,
sizeof(timebuf),
"%02d:%02d:%02d.%06ld",
124 (
int)now->tm_hour, (
int)now->tm_min, (
int)now->tm_sec, (
long)tv.
tv_usec);
127 vsnprintf(buffer,
sizeof(buffer), msg, ap);
132 fprintf(logfp,
"%s %s\n", timebuf, buffer);
137 fprintf(stderr,
"fopen() failed with error: %d %s\n",
138 error, strerror(error));
140 fprintf(stderr,
"Msg not logged: %s %s\n", timebuf, buffer);
146 void win32_perror(
const char *msg)
151 if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
152 LANG_NEUTRAL, buf,
sizeof(buf), NULL))
153 snprintf(buf,
sizeof(buf),
"Unknown error %lu (%#lx)", err, err);
163 WORD wVersionRequested;
166 wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
168 err = WSAStartup(wVersionRequested, &wsaData);
171 perror(
"Winsock init failed");
172 logmsg(
"Error initialising winsock -- aborting");
176 if(LOBYTE(wsaData.wVersion) != USE_WINSOCK ||
177 HIBYTE(wsaData.wVersion) != USE_WINSOCK) {
179 perror(
"Winsock init failed");
180 logmsg(
"No suitable winsock.dll found -- aborting");
212 #if !defined(MSDOS) && !defined(USE_WINSOCK) 213 #ifndef HAVE_POLL_FINE 230 #elif defined(USE_WINSOCK) 233 pending_ms = timeout_ms;
236 #if defined(HAVE_POLL_FINE) 237 r = poll(NULL, 0, pending_ms);
239 pending_tv.
tv_sec = pending_ms / 1000;
240 pending_tv.
tv_usec = (pending_ms % 1000) * 1000;
241 r = select(0, NULL, NULL, NULL, &pending_tv);
246 if(error && (error != EINTR))
263 pid = (long)getpid();
264 pidfile = fopen(filename,
"wb");
266 logmsg(
"Couldn't write pid file: %s %s", filename, strerror(errno));
269 fprintf(pidfile,
"%ld\n", pid);
271 logmsg(
"Wrote pid %ld to %s", pid, filename);
282 lockfile = fopen(filename,
"wb");
283 }
while((lockfile == NULL) && ((error = errno) == EINTR));
284 if(lockfile == NULL) {
285 logmsg(
"Error creating lock file %s error: %d %s",
286 filename, error, strerror(error));
291 res = fclose(lockfile);
292 }
while(res && ((error = errno) == EINTR));
294 logmsg(
"Error closing lock file %s error: %d %s",
295 filename, error, strerror(error));
310 res = unlink(filename);
311 }
while(res && ((error = errno) == EINTR));
313 logmsg(
"Error removing lock file %s error: %d %s",
314 filename, error, strerror(error));
322 #if !defined(CURL_DOES_CONVERSIONS) 323 if(in >=
'a' && in <=
'z')
324 return (
char)(
'A' + in -
'a');
387 while(*first && *second && max) {
const char * serverlogfile
char * data_to_hex(char *data, size_t len)
struct curltime curlx_tvnow(void)
int write_pidfile(const char *filename)
static void win32_cleanup(void)
void clear_advisor_read_lock(const char *filename)
static time_t epoch_offset
static char raw_toupper(char in)
void logmsg(const char *msg,...)
UNITTEST_START struct Curl_easy data
int strncasecompare(const char *first, const char *second, size_t max)
time_t curlx_tvdiff(struct curltime newer, struct curltime older)
static CURLcode win32_init(void)
char * test2file(long testno)
void set_advisor_read_lock(const char *filename)
int wait_ms(int timeout_ms)