diff options
Diffstat (limited to '')
-rw-r--r-- | common/ChangeLog | 8 | ||||
-rw-r--r-- | common/asshelp.c | 6 | ||||
-rw-r--r-- | common/b64enc.c | 6 | ||||
-rw-r--r-- | common/exechelp.c | 14 | ||||
-rw-r--r-- | common/http.c | 62 | ||||
-rw-r--r-- | common/iobuf.c | 16 | ||||
-rw-r--r-- | common/miscellaneous.c | 2 | ||||
-rw-r--r-- | common/util.h | 4 |
8 files changed, 68 insertions, 50 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index 88dfdff9c..e24250c17 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,11 @@ +2006-09-14 Werner Koch <[email protected]> + + * util.h (out_of_core): Use new gpg_error_from_syserror function. + + * http.c (init_sockets): Changed it to require 2.2 unless it is + build within gnupg 1 where we require 1.1 (and not anymore allow + for 1.0). + 2006-09-07 Werner Koch <[email protected]> * exechelp.c (gnupg_spawn_process): Factor out post fork code to .. diff --git a/common/asshelp.c b/common/asshelp.c index 3b46b5ed3..54d7224d8 100644 --- a/common/asshelp.c +++ b/common/asshelp.c @@ -44,7 +44,7 @@ send_one_option (assuan_context_t ctx, gpg_err_source_t errsource, if (!value || !*value) err = 0; /* Avoid sending empty strings. */ else if (asprintf (&optstr, "OPTION %s=%s", name, value ) < 0) - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); else { err = assuan_transact (ctx, optstr, NULL, NULL, NULL, NULL, NULL, NULL); @@ -116,7 +116,7 @@ send_pinentry_environment (assuan_context_t ctx, { old_lc = strdup (old_lc); if (!old_lc) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } dft_lc = setlocale (LC_CTYPE, ""); #endif @@ -142,7 +142,7 @@ send_pinentry_environment (assuan_context_t ctx, { old_lc = strdup (old_lc); if (!old_lc) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } dft_lc = setlocale (LC_MESSAGES, ""); #endif diff --git a/common/b64enc.c b/common/b64enc.c index bfc49deb6..73e3d4f64 100644 --- a/common/b64enc.c +++ b/common/b64enc.c @@ -57,7 +57,7 @@ b64enc_start (struct b64state *state, FILE *fp, const char *title) { state->title = xtrystrdup (title); if (!state->title) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } return 0; } @@ -130,7 +130,7 @@ b64enc_write (struct b64state *state, const void *buffer, size_t nbytes) return 0; write_error: - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } gpg_error_t @@ -200,7 +200,7 @@ b64enc_finish (struct b64state *state) goto cleanup; write_error: - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); cleanup: if (state->title) diff --git a/common/exechelp.c b/common/exechelp.c index cfb76c2f5..19fb04ffa 100644 --- a/common/exechelp.c +++ b/common/exechelp.c @@ -96,7 +96,7 @@ build_w32_commandline (const char *pgmname, const char **argv, char **cmdline) buf = p = xtrymalloc (n); if (!buf) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); /* fixme: PGMNAME may not contain spaces etc. */ p = stpcpy (p, pgmname); @@ -342,7 +342,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], } if (!*statusfile) { - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); log_error (_("can't fdopen pipe for reading: %s\n"), gpg_strerror (err)); CloseHandle (pi.hProcess); return err; @@ -366,7 +366,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], if (pipe (rp) == -1) { - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); log_error (_("error creating a pipe: %s\n"), strerror (errno)); return err; } @@ -378,7 +378,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], #endif if (*pid == (pid_t)(-1)) { - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); log_error (_("error forking process: %s\n"), strerror (errno)); close (rp[0]); close (rp[1]); @@ -399,7 +399,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[], *statusfile = fdopen (rp[0], "r"); if (!*statusfile) { - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); log_error (_("can't fdopen pipe for reading: %s\n"), strerror (errno)); kill (*pid, SIGTERM); *pid = (pid_t)(-1); @@ -528,7 +528,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[], return gpg_error (GPG_ERR_BUG); if (access (pgmname, X_OK)) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); #ifdef USE_GNU_PTH pid = pth_fork? pth_fork () : fork (); @@ -538,7 +538,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[], if (pid == (pid_t)(-1)) { log_error (_("error forking process: %s\n"), strerror (errno)); - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } if (!pid) { diff --git a/common/http.c b/common/http.c index 83b6216cc..3720b00af 100644 --- a/common/http.c +++ b/common/http.c @@ -200,6 +200,16 @@ struct http_context_s #ifdef HAVE_W32_SYSTEM + +#if GNUPG_MAJOR_VERSION == 1 +#define REQ_WINSOCK_MAJOR 1 +#define REQ_WINSOCK_MINOR 1 +#else +#define REQ_WINSOCK_MAJOR 2 +#define REQ_WINSOCK_MINOR 2 +#endif + + static void deinit_sockets (void) { @@ -215,16 +225,18 @@ init_sockets (void) if (initialized) return; - if ( WSAStartup( 0x0101, &wsdata ) ) + if ( WSAStartup( MAKEWORD (REQ_WINSOCK_MINOR, REQ_WINSOCK_MAJOR), &wsdata ) ) { log_error ("error initializing socket library: ec=%d\n", (int)WSAGetLastError () ); return; } - if ( wsdata.wVersion < 0x0001 ) + if ( LOBYTE(wsdata.wVersion) != REQ_WINSOCK_MAJOR + || HIBYTE(wsdata.wVersion) != REQ_WINSOCK_MINOR ) { - log_error ("socket library version is %x.%x - but 1.1 needed\n", - LOBYTE(wsdata.wVersion), HIBYTE(wsdata.wVersion)); + log_error ("socket library version is %x.%x - but %d.%d needed\n", + LOBYTE(wsdata.wVersion), HIBYTE(wsdata.wVersion) + REQ_WINSOCK_MAJOR, REQ_WINSOCK_MINOR); WSACleanup(); return; } @@ -313,7 +325,7 @@ http_open (http_t *r_hd, http_req_t reqtype, const char *url, /* Create the handle. */ hd = xtrycalloc (1, sizeof *hd); if (!hd) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); hd->sock = -1; hd->req_type = reqtype; hd->flags = flags; @@ -383,7 +395,7 @@ http_wait_response (http_t hd) { hd->sock = dup (hd->sock); if (hd->sock == -1) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } P_ES(fclose) (hd->fp_write); hd->fp_write = NULL; @@ -401,7 +413,7 @@ http_wait_response (http_t hd) cookie = xtrycalloc (1, sizeof *cookie); if (!cookie) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); cookie->fd = hd->sock; if (hd->uri->use_tls) cookie->tls_session = hd->tls_context; @@ -410,13 +422,13 @@ http_wait_response (http_t hd) if (!hd->fp_read) { xfree (cookie); - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } } #else /*!HTTP_USE_ESTREAM*/ hd->fp_read = fdopen (hd->sock, "r"); if (!hd->fp_read) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); #endif /*!HTTP_USE_ESTREAM*/ err = parse_response (hd); @@ -851,7 +863,7 @@ send_request (http_t hd, const char *auth, const char *proxy) uri->auth, strlen(uri->auth)); if (!proxy_authstr) { - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); http_release_parsed_uri (uri); return err; } @@ -919,7 +931,7 @@ send_request (http_t hd, const char *auth, const char *proxy) if (!myauth) { xfree (proxy_authstr); - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } remove_escapes (myauth); } @@ -937,13 +949,13 @@ send_request (http_t hd, const char *auth, const char *proxy) if (!authstr) { xfree (proxy_authstr); - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } } p = build_rel_path (hd->uri); if (!p) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); request = xtrymalloc (2 * strlen (server) + strlen (p) @@ -952,7 +964,7 @@ send_request (http_t hd, const char *auth, const char *proxy) + 100); if (!request) { - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); xfree (p); xfree (authstr); xfree (proxy_authstr); @@ -997,7 +1009,7 @@ send_request (http_t hd, const char *auth, const char *proxy) cookie = xtrycalloc (1, sizeof *cookie); if (!cookie) { - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); goto leave; } cookie->fd = hd->sock; @@ -1011,10 +1023,10 @@ send_request (http_t hd, const char *auth, const char *proxy) if (!hd->fp_write) { xfree (cookie); - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); } else if (es_fputs (request, hd->fp_write) || es_fflush (hd->fp_write)) - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); else err = 0; } @@ -1030,7 +1042,7 @@ send_request (http_t hd, const char *auth, const char *proxy) { hd->fp_write = fdopen (hd->sock, "w"); if (!hd->fp_write) - err = gpg_error_from_errno (errno); + err = gpg_error_from_syserror (); } #endif /*!HTTP_USE_ESTREAM*/ @@ -1237,7 +1249,7 @@ store_header (http_t hd, char *line) n += strlen (hd->headers->value); p = xtrymalloc (n+1); if (!p) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); strcpy (stpcpy (p, hd->headers->value), line); xfree (hd->headers->value); hd->headers->value = p; @@ -1262,7 +1274,7 @@ store_header (http_t hd, char *line) it is a comma separated list and merge them. */ p = xtrymalloc (strlen (h->value) + 1 + strlen (value)+ 1); if (!p) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); strcpy (stpcpy (stpcpy (p, h->value), ","), value); xfree (h->value); h->value = p; @@ -1272,13 +1284,13 @@ store_header (http_t hd, char *line) /* Append a new header. */ h = xtrymalloc (sizeof *h + strlen (line)); if (!h) - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); strcpy (h->name, line); h->value = xtrymalloc (strlen (value)+1); if (!h->value) { xfree (h); - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } strcpy (h->value, value); h->next = hd->headers; @@ -1334,7 +1346,7 @@ parse_response (http_t hd) len = my_read_line (hd->fp_read, &hd->buffer, &hd->buffer_size, &maxlen); line = hd->buffer; if (!line) - return gpg_error_from_errno (errno); /* Out of core. */ + return gpg_error_from_syserror (); /* Out of core. */ if (!maxlen) return gpg_error (GPG_ERR_TRUNCATED); /* Line has been truncated. */ if (!len) @@ -1378,7 +1390,7 @@ parse_response (http_t hd) len = my_read_line (hd->fp_read, &hd->buffer, &hd->buffer_size, &maxlen); line = hd->buffer; if (!line) - return gpg_error_from_errno (errno); /* Out of core. */ + return gpg_error_from_syserror (); /* Out of core. */ /* Note, that we can silently ignore truncated lines. */ if (!len) return gpg_error (GPG_ERR_EOF); @@ -1700,7 +1712,7 @@ write_server (int sock, const char *data, size_t length) continue; } log_info ("network write failed: %s\n", strerror (errno)); - return gpg_error_from_errno (errno); + return gpg_error_from_syserror (); } #endif /*!HAVE_W32_SYSTEM*/ nleft -= nwritten; diff --git a/common/iobuf.c b/common/iobuf.c index 8f7374f8c..b15d76a0a 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -392,7 +392,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf, } else if (ferror (f) && errno != EPIPE) { - rc = gpg_error_from_errno (errno); + rc = gpg_error_from_syserror (); log_error ("%s: read error: %s\n", a->fname, strerror (errno)); } *ret_len = nbytes; @@ -406,7 +406,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf, nbytes = fwrite (buf, 1, size, f); if (ferror (f)) { - rc = gpg_error_from_errno (errno); + rc = gpg_error_from_syserror (); log_error ("%s: write error: %s\n", a->fname, strerror (errno)); } } @@ -481,7 +481,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf, { /* error */ if (errno != EPIPE) { - rc = gpg_error_from_errno (errno); + rc = gpg_error_from_syserror (); log_error ("%s: read error: %s\n", a->fname, strerror (errno)); } @@ -543,7 +543,7 @@ file_filter (void *opaque, int control, iobuf_t chain, byte * buf, while (n != -1 && nbytes); if (n == -1) { - rc = gpg_error_from_errno (errno); + rc = gpg_error_from_syserror (); log_error ("%s: write error: %s\n", a->fname, strerror (errno)); } nbytes = p - buf; @@ -849,14 +849,14 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer, { /* write stuff from the buffer */ assert (n == OP_MIN_PARTIAL_CHUNK); if (iobuf_write (chain, a->buffer, n)) - rc = gpg_error_from_errno (errno); + rc = gpg_error_from_syserror (); a->buflen = 0; nbytes -= n; } if ((n = nbytes) > blen) n = blen; if (n && iobuf_write (chain, p, n)) - rc = gpg_error_from_errno (errno); + rc = gpg_error_from_syserror (); p += n; nbytes -= n; } @@ -935,7 +935,7 @@ block_filter (void *opaque, int control, iobuf_t chain, byte * buffer, { log_error ("block_filter: write error: %s\n", strerror (errno)); - rc = gpg_error_from_errno (errno); + rc = gpg_error_from_syserror (); } xfree (a->buffer); a->buffer = NULL; @@ -1649,7 +1649,7 @@ underflow (iobuf_t a) if (len < a->d.size) { if (ferror (fp)) - a->error = gpg_error_from_errno (errno); + a->error = gpg_error_from_syserror (); } a->d.len = len; a->d.start = 0; diff --git a/common/miscellaneous.c b/common/miscellaneous.c index da74f65bc..364f13489 100644 --- a/common/miscellaneous.c +++ b/common/miscellaneous.c @@ -99,7 +99,7 @@ is_file_compressed (const char *s, int *ret_rc) a = iobuf_open( s ); if ( a == NULL ) { - *ret_rc = gpg_error_from_errno (errno); + *ret_rc = gpg_error_from_syserror (); return 0; } diff --git a/common/util.h b/common/util.h index 10828d7e5..92b88aa8d 100644 --- a/common/util.h +++ b/common/util.h @@ -71,9 +71,7 @@ static inline gpg_error_t out_of_core (void) { - return gpg_error (errno - ? gpg_err_code_from_errno(errno) - : GPG_ERR_MISSING_ERRNO); + return gpg_error_from_syserror (); } /* A type to hold the ISO time. Note that this this is the same as |