mirror of
https://github.com/curl/curl.git
synced 2026-08-26 03:53:32 +03:00
Moved more generic functions to util.[ch]
Added resolve.c to simply resolve a given host name
This commit is contained in:
parent
ede9fb4fcc
commit
84fd4686e2
6 changed files with 238 additions and 157 deletions
|
|
@ -96,3 +96,52 @@ void logmsg(const char *msg, ...)
|
|||
if(logfp)
|
||||
fclose(logfp);
|
||||
}
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
/* use instead of perror() on generic windows */
|
||||
void win32_perror (const char *msg)
|
||||
{
|
||||
char buf[256];
|
||||
DWORD err = WSAGetLastError();
|
||||
|
||||
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
|
||||
LANG_NEUTRAL, buf, sizeof(buf), NULL))
|
||||
snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
|
||||
if (msg)
|
||||
fprintf(stderr, "%s: ", msg);
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||
void win32_init(void)
|
||||
{
|
||||
WORD wVersionRequested;
|
||||
WSADATA wsaData;
|
||||
int err;
|
||||
wVersionRequested = MAKEWORD(2, 0);
|
||||
|
||||
err = WSAStartup(wVersionRequested, &wsaData);
|
||||
|
||||
if (err != 0) {
|
||||
perror("Winsock init failed");
|
||||
logmsg("Error initialising winsock -- aborting\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if ( LOBYTE( wsaData.wVersion ) != 2 ||
|
||||
HIBYTE( wsaData.wVersion ) != 0 ) {
|
||||
|
||||
WSACleanup();
|
||||
perror("Winsock init failed");
|
||||
logmsg("No suitable winsock.dll found -- aborting\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void win32_cleanup(void)
|
||||
{
|
||||
WSACleanup();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue