mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
use macros ERRNO, SET_ERRNO(), SOCKERRNO and SET_SOCKERRNO() for errno handling
This commit is contained in:
parent
aa4435c23b
commit
4894ce16fc
@ -1319,11 +1319,11 @@ static int str2offset(curl_off_t *val, char *str)
|
|||||||
/* this is a duplicate of the function that is also used in libcurl */
|
/* this is a duplicate of the function that is also used in libcurl */
|
||||||
*val = curlx_strtoofft(str, NULL, 0);
|
*val = curlx_strtoofft(str, NULL, 0);
|
||||||
|
|
||||||
if ((*val == LLONG_MAX || *val == LLONG_MIN) && errno == ERANGE)
|
if ((*val == LLONG_MAX || *val == LLONG_MIN) && ERRNO == ERANGE)
|
||||||
return 1;
|
return 1;
|
||||||
#else
|
#else
|
||||||
*val = strtol(str, NULL, 0);
|
*val = strtol(str, NULL, 0);
|
||||||
if ((*val == LONG_MIN || *val == LONG_MAX) && errno == ERANGE)
|
if ((*val == LONG_MIN || *val == LONG_MAX) && ERRNO == ERANGE)
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
@ -4621,6 +4621,7 @@ static int create_dir_hierarchy(char *outfile)
|
|||||||
char *outdup;
|
char *outdup;
|
||||||
char *dirbuildup;
|
char *dirbuildup;
|
||||||
int result=0;
|
int result=0;
|
||||||
|
int error;
|
||||||
|
|
||||||
outdup = strdup(outfile);
|
outdup = strdup(outfile);
|
||||||
dirbuildup = malloc(sizeof(char) * strlen(outfile));
|
dirbuildup = malloc(sizeof(char) * strlen(outfile));
|
||||||
@ -4646,7 +4647,8 @@ static int create_dir_hierarchy(char *outfile)
|
|||||||
if (access(dirbuildup, F_OK) == -1) {
|
if (access(dirbuildup, F_OK) == -1) {
|
||||||
result = mkdir(dirbuildup,(mode_t)0000750);
|
result = mkdir(dirbuildup,(mode_t)0000750);
|
||||||
if (-1 == result) {
|
if (-1 == result) {
|
||||||
switch (errno) {
|
error = ERRNO;
|
||||||
|
switch (error) {
|
||||||
#ifdef EACCES
|
#ifdef EACCES
|
||||||
case EACCES:
|
case EACCES:
|
||||||
fprintf(stderr,"You don't have permission to create %s.\n",
|
fprintf(stderr,"You don't have permission to create %s.\n",
|
||||||
|
@ -46,20 +46,6 @@ static int *fd = NULL;
|
|||||||
static struct rlimit num_open;
|
static struct rlimit num_open;
|
||||||
static char msgbuff[256];
|
static char msgbuff[256];
|
||||||
|
|
||||||
/*
|
|
||||||
* our_errno() returns the NOT *socket-related* errno (or equivalent)
|
|
||||||
* on this platform to hide platform specific for the calling function.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int our_errno(void)
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
return (int)GetLastError();
|
|
||||||
#else
|
|
||||||
return errno;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void store_errmsg(const char *msg, int err)
|
static void store_errmsg(const char *msg, int err)
|
||||||
{
|
{
|
||||||
if (!err)
|
if (!err)
|
||||||
@ -102,7 +88,7 @@ static int rlimit(int keep_open)
|
|||||||
/* get initial open file limits */
|
/* get initial open file limits */
|
||||||
|
|
||||||
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||||
store_errmsg("getrlimit() failed", our_errno());
|
store_errmsg("getrlimit() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -145,7 +131,7 @@ static int rlimit(int keep_open)
|
|||||||
fprintf(stderr, "raising soft limit up to hard limit\n");
|
fprintf(stderr, "raising soft limit up to hard limit\n");
|
||||||
rl.rlim_cur = rl.rlim_max;
|
rl.rlim_cur = rl.rlim_max;
|
||||||
if (setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
if (setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||||
store_errmsg("setrlimit() failed", our_errno());
|
store_errmsg("setrlimit() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
@ -153,7 +139,7 @@ static int rlimit(int keep_open)
|
|||||||
/* get current open file limits */
|
/* get current open file limits */
|
||||||
|
|
||||||
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||||
store_errmsg("getrlimit() failed", our_errno());
|
store_errmsg("getrlimit() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
@ -233,7 +219,7 @@ static int rlimit(int keep_open)
|
|||||||
}
|
}
|
||||||
} while (nitems && !memchunk);
|
} while (nitems && !memchunk);
|
||||||
if (!memchunk) {
|
if (!memchunk) {
|
||||||
store_errmsg("memchunk, malloc() failed", our_errno());
|
store_errmsg("memchunk, malloc() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
@ -268,7 +254,7 @@ static int rlimit(int keep_open)
|
|||||||
|
|
||||||
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
|
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
store_errmsg("fd, malloc() failed", our_errno());
|
store_errmsg("fd, malloc() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
free(memchunk);
|
free(memchunk);
|
||||||
return -7;
|
return -7;
|
||||||
@ -291,7 +277,7 @@ static int rlimit(int keep_open)
|
|||||||
fd[0] = open(DEV_NULL, O_RDONLY);
|
fd[0] = open(DEV_NULL, O_RDONLY);
|
||||||
if (fd[0] < 0) {
|
if (fd[0] < 0) {
|
||||||
sprintf(strbuff, "opening of %s failed", DEV_NULL);
|
sprintf(strbuff, "opening of %s failed", DEV_NULL);
|
||||||
store_errmsg(strbuff, our_errno());
|
store_errmsg(strbuff, ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
free(fd);
|
free(fd);
|
||||||
fd = NULL;
|
fd = NULL;
|
||||||
|
@ -48,20 +48,6 @@ static int *fd = NULL;
|
|||||||
static struct rlimit num_open;
|
static struct rlimit num_open;
|
||||||
static char msgbuff[256];
|
static char msgbuff[256];
|
||||||
|
|
||||||
/*
|
|
||||||
* our_errno() returns the NOT *socket-related* errno (or equivalent)
|
|
||||||
* on this platform to hide platform specific for the calling function.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int our_errno(void)
|
|
||||||
{
|
|
||||||
#ifdef WIN32
|
|
||||||
return (int)GetLastError();
|
|
||||||
#else
|
|
||||||
return errno;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void store_errmsg(const char *msg, int err)
|
static void store_errmsg(const char *msg, int err)
|
||||||
{
|
{
|
||||||
if (!err)
|
if (!err)
|
||||||
@ -104,7 +90,7 @@ static int rlimit(int keep_open)
|
|||||||
/* get initial open file limits */
|
/* get initial open file limits */
|
||||||
|
|
||||||
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||||
store_errmsg("getrlimit() failed", our_errno());
|
store_errmsg("getrlimit() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -141,7 +127,7 @@ static int rlimit(int keep_open)
|
|||||||
fprintf(stderr, "raising soft limit up to hard limit\n");
|
fprintf(stderr, "raising soft limit up to hard limit\n");
|
||||||
rl.rlim_cur = rl.rlim_max;
|
rl.rlim_cur = rl.rlim_max;
|
||||||
if (setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
if (setrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||||
store_errmsg("setrlimit() failed", our_errno());
|
store_errmsg("setrlimit() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
@ -149,7 +135,7 @@ static int rlimit(int keep_open)
|
|||||||
/* get current open file limits */
|
/* get current open file limits */
|
||||||
|
|
||||||
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
if (getrlimit(RLIMIT_NOFILE, &rl) != 0) {
|
||||||
store_errmsg("getrlimit() failed", our_errno());
|
store_errmsg("getrlimit() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
@ -208,7 +194,7 @@ static int rlimit(int keep_open)
|
|||||||
}
|
}
|
||||||
} while (nitems && !memchunk);
|
} while (nitems && !memchunk);
|
||||||
if (!memchunk) {
|
if (!memchunk) {
|
||||||
store_errmsg("memchunk, malloc() failed", our_errno());
|
store_errmsg("memchunk, malloc() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
@ -263,7 +249,7 @@ static int rlimit(int keep_open)
|
|||||||
}
|
}
|
||||||
} while (num_open.rlim_max && !fd);
|
} while (num_open.rlim_max && !fd);
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
store_errmsg("fd, malloc() failed", our_errno());
|
store_errmsg("fd, malloc() failed", ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
free(memchunk);
|
free(memchunk);
|
||||||
return -6;
|
return -6;
|
||||||
@ -286,7 +272,7 @@ static int rlimit(int keep_open)
|
|||||||
fd[0] = open(DEV_NULL, O_RDONLY);
|
fd[0] = open(DEV_NULL, O_RDONLY);
|
||||||
if (fd[0] < 0) {
|
if (fd[0] < 0) {
|
||||||
sprintf(strbuff, "opening of %s failed", DEV_NULL);
|
sprintf(strbuff, "opening of %s failed", DEV_NULL);
|
||||||
store_errmsg(strbuff, our_errno());
|
store_errmsg(strbuff, ERRNO);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
free(fd);
|
free(fd);
|
||||||
fd = NULL;
|
fd = NULL;
|
||||||
|
@ -8,18 +8,17 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
/* Now include the setup.h file from libcurl's private libdir (the source
|
/* Now include the setup.h file from libcurl's private libdir (the source
|
||||||
version, but that might include "config.h" from the build dir so we need
|
version, but that might include "config.h" from the build dir so we need
|
||||||
both of them in the include path), so that we get good in-depth knowledge
|
both of them in the include path), so that we get good in-depth knowledge
|
||||||
about the system we're building this on */
|
about the system we're building this on */
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <curl.h>
|
#include <curl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
#ifdef HAVE_SYS_SOCKET_H
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
@ -238,7 +238,7 @@ static int juggle(curl_socket_t *sockfdp,
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
rc = select(maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout);
|
rc = select(maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout);
|
||||||
} while((rc == -1) && (our_sockerrno() == EINTR));
|
} while((rc == -1) && (SOCKERRNO == EINTR));
|
||||||
|
|
||||||
switch(rc) {
|
switch(rc) {
|
||||||
case -1:
|
case -1:
|
||||||
@ -447,7 +447,7 @@ static curl_socket_t sockdaemon(curl_socket_t sock,
|
|||||||
/* start accepting connections */
|
/* start accepting connections */
|
||||||
rc = listen(sock, 4);
|
rc = listen(sock, 4);
|
||||||
if(0 != rc) {
|
if(0 != rc) {
|
||||||
logmsg("listen() failed with error: %d", errno);
|
logmsg("listen() failed with error: %d", SOCKERRNO);
|
||||||
sclose(sock);
|
sclose(sock);
|
||||||
return CURL_SOCKET_BAD;
|
return CURL_SOCKET_BAD;
|
||||||
}
|
}
|
||||||
@ -570,7 +570,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
sock = mksock(use_ipv6);
|
sock = mksock(use_ipv6);
|
||||||
if (CURL_SOCKET_BAD == sock) {
|
if (CURL_SOCKET_BAD == sock) {
|
||||||
logmsg("Error opening socket: %d", errno);
|
logmsg("Error opening socket: %d", SOCKERRNO);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ void storerequest(char *reqbuf)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
dump = fopen(REQUEST_DUMP, "ab");
|
dump = fopen(REQUEST_DUMP, "ab");
|
||||||
} while ((dump == NULL) && ((error = errno) == EINTR));
|
} while ((dump == NULL) && ((error = ERRNO) == EINTR));
|
||||||
if (dump == NULL) {
|
if (dump == NULL) {
|
||||||
logmsg("Error opening file %s error: %d", REQUEST_DUMP, error);
|
logmsg("Error opening file %s error: %d", REQUEST_DUMP, error);
|
||||||
logmsg("Failed to write request input to " REQUEST_DUMP);
|
logmsg("Failed to write request input to " REQUEST_DUMP);
|
||||||
@ -479,7 +479,7 @@ void storerequest(char *reqbuf)
|
|||||||
1, (size_t)writeleft, dump);
|
1, (size_t)writeleft, dump);
|
||||||
if (written > 0)
|
if (written > 0)
|
||||||
writeleft -= written;
|
writeleft -= written;
|
||||||
} while ((writeleft > 0) && ((error = errno) == EINTR));
|
} while ((writeleft > 0) && ((error = ERRNO) == EINTR));
|
||||||
|
|
||||||
fclose(dump); /* close it ASAP */
|
fclose(dump); /* close it ASAP */
|
||||||
|
|
||||||
@ -515,7 +515,7 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
|
|||||||
ssize_t got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset);
|
ssize_t got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset);
|
||||||
if (got <= 0) {
|
if (got <= 0) {
|
||||||
if (got < 0) {
|
if (got < 0) {
|
||||||
logmsg("recv() returned error: %d", errno);
|
logmsg("recv() returned error: %d", SOCKERRNO);
|
||||||
return DOCNUMBER_INTERNAL;
|
return DOCNUMBER_INTERNAL;
|
||||||
}
|
}
|
||||||
logmsg("Connection closed by client");
|
logmsg("Connection closed by client");
|
||||||
@ -830,14 +830,14 @@ int main(int argc, char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (CURL_SOCKET_BAD == sock) {
|
if (CURL_SOCKET_BAD == sock) {
|
||||||
logmsg("Error opening socket: %d", errno);
|
logmsg("Error opening socket: %d", SOCKERRNO);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
flag = 1;
|
flag = 1;
|
||||||
if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
||||||
(void *) &flag, sizeof(flag))) {
|
(void *) &flag, sizeof(flag))) {
|
||||||
logmsg("setsockopt(SO_REUSEADDR) failed: %d", errno);
|
logmsg("setsockopt(SO_REUSEADDR) failed: %d", SOCKERRNO);
|
||||||
sclose(sock);
|
sclose(sock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -861,7 +861,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif /* ENABLE_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
if(0 != rc) {
|
if(0 != rc) {
|
||||||
logmsg("Error binding socket: %d", errno);
|
logmsg("Error binding socket: %d", SOCKERRNO);
|
||||||
sclose(sock);
|
sclose(sock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -888,7 +888,7 @@ int main(int argc, char *argv[])
|
|||||||
/* start accepting connections */
|
/* start accepting connections */
|
||||||
rc = listen(sock, 5);
|
rc = listen(sock, 5);
|
||||||
if(0 != rc) {
|
if(0 != rc) {
|
||||||
logmsg("listen() failed with error: %d", errno);
|
logmsg("listen() failed with error: %d", SOCKERRNO);
|
||||||
sclose(sock);
|
sclose(sock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -897,7 +897,7 @@ int main(int argc, char *argv[])
|
|||||||
msgsock = accept(sock, NULL, NULL);
|
msgsock = accept(sock, NULL, NULL);
|
||||||
|
|
||||||
if (CURL_SOCKET_BAD == msgsock) {
|
if (CURL_SOCKET_BAD == msgsock) {
|
||||||
printf("MAJOR ERROR: accept() failed with error: %d\n", errno);
|
printf("MAJOR ERROR: accept() failed with error: %d\n", SOCKERRNO);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,7 +749,7 @@ static void sendtftp(struct testcase *test, struct formats *pf)
|
|||||||
do {
|
do {
|
||||||
size = readit(test, &dp, pf->f_convert);
|
size = readit(test, &dp, pf->f_convert);
|
||||||
if (size < 0) {
|
if (size < 0) {
|
||||||
nak(errno + 100);
|
nak(ERRNO + 100);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dp->th_opcode = htons((u_short)DATA);
|
dp->th_opcode = htons((u_short)DATA);
|
||||||
@ -864,7 +864,7 @@ send_ack:
|
|||||||
size = writeit(test, &dp, (int)(n - 4), pf->f_convert);
|
size = writeit(test, &dp, (int)(n - 4), pf->f_convert);
|
||||||
if (size != (n-4)) { /* ahem */
|
if (size != (n-4)) { /* ahem */
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
nak(errno + 100);
|
nak(ERRNO + 100);
|
||||||
else
|
else
|
||||||
nak(ENOSPACE);
|
nak(ENOSPACE);
|
||||||
goto abort;
|
goto abort;
|
||||||
|
@ -59,19 +59,6 @@
|
|||||||
const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }};
|
const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
|
||||||
* our_sockerrno() returns the *socket-related* errno (or equivalent) on this
|
|
||||||
* platform to hide platform specific for the function that calls this.
|
|
||||||
*/
|
|
||||||
int our_sockerrno(void)
|
|
||||||
{
|
|
||||||
#ifdef USE_WINSOCK
|
|
||||||
return (int)WSAGetLastError();
|
|
||||||
#else
|
|
||||||
return errno;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* someone else must set this properly */
|
/* someone else must set this properly */
|
||||||
extern const char *serverlogfile;
|
extern const char *serverlogfile;
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
* $Id$
|
* $Id$
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
int our_sockerrno(void);
|
|
||||||
void logmsg(const char *msg, ...);
|
void logmsg(const char *msg, ...);
|
||||||
|
|
||||||
#ifndef FALSE
|
#ifndef FALSE
|
||||||
|
Loading…
Reference in New Issue
Block a user