mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Replace most of the remaining stdio calls by estream calls.
--
We need to use es_fopen on Windows to cope with non-ascii file names.
This is quite a large but fortunately straightforward change. At a
very few places we keep using stdio (for example due to the use of
popen).
GnuPG-bug-id: 5098
Signed-off-by: Werner Koch <wk@gnupg.org>
Backported-from-master: 390497ea11
This commit is contained in:
parent
dd5fd4a760
commit
5c6e9b44cc
20 changed files with 208 additions and 197 deletions
|
@ -227,7 +227,7 @@ main (int argc, char **argv )
|
|||
static char *
|
||||
read_file (const char *fname, size_t *r_length)
|
||||
{
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
|
||||
|
@ -235,10 +235,8 @@ read_file (const char *fname, size_t *r_length)
|
|||
{
|
||||
size_t nread, bufsize = 0;
|
||||
|
||||
fp = stdin;
|
||||
#ifdef HAVE_DOSISH_SYSTEM
|
||||
setmode ( fileno(fp) , O_BINARY );
|
||||
#endif
|
||||
fp = es_stdin;
|
||||
es_set_binary (fp);
|
||||
buf = NULL;
|
||||
buflen = 0;
|
||||
#define NCHUNK 8192
|
||||
|
@ -250,8 +248,8 @@ read_file (const char *fname, size_t *r_length)
|
|||
else
|
||||
buf = xrealloc (buf, bufsize+1);
|
||||
|
||||
nread = fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && ferror (fp))
|
||||
nread = es_fread (buf+buflen, 1, NCHUNK, fp);
|
||||
if (nread < NCHUNK && es_ferror (fp))
|
||||
{
|
||||
log_error ("error reading '[stdin]': %s\n", strerror (errno));
|
||||
xfree (buf);
|
||||
|
@ -267,30 +265,30 @@ read_file (const char *fname, size_t *r_length)
|
|||
{
|
||||
struct stat st;
|
||||
|
||||
fp = fopen (fname, "rb");
|
||||
fp = es_fopen (fname, "rb");
|
||||
if (!fp)
|
||||
{
|
||||
log_error ("can't open '%s': %s\n", fname, strerror (errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fstat (fileno(fp), &st))
|
||||
if (fstat (es_fileno (fp), &st))
|
||||
{
|
||||
log_error ("can't stat '%s': %s\n", fname, strerror (errno));
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
buflen = st.st_size;
|
||||
buf = xmalloc (buflen+1);
|
||||
if (fread (buf, buflen, 1, fp) != 1)
|
||||
if (es_fread (buf, buflen, 1, fp) != 1)
|
||||
{
|
||||
log_error ("error reading '%s': %s\n", fname, strerror (errno));
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
xfree (buf);
|
||||
return NULL;
|
||||
}
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
}
|
||||
buf[buflen] = 0;
|
||||
*r_length = buflen;
|
||||
|
|
|
@ -166,7 +166,7 @@ typedef struct loopline_s *loopline_t;
|
|||
static pid_t server_pid = (pid_t)(-1);
|
||||
|
||||
/* The current datasink file or NULL. */
|
||||
static FILE *current_datasink;
|
||||
static estream_t current_datasink;
|
||||
|
||||
/* A list of open file descriptors. */
|
||||
static struct
|
||||
|
@ -874,7 +874,7 @@ clear_definq (void)
|
|||
static void
|
||||
do_sendfd (assuan_context_t ctx, char *line)
|
||||
{
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
char *name, *mode, *p;
|
||||
int rc, fd;
|
||||
|
||||
|
@ -900,14 +900,14 @@ do_sendfd (assuan_context_t ctx, char *line)
|
|||
}
|
||||
|
||||
/* Open and send. */
|
||||
fp = fopen (name, mode);
|
||||
fp = es_fopen (name, mode);
|
||||
if (!fp)
|
||||
{
|
||||
log_error ("can't open '%s' in \"%s\" mode: %s\n",
|
||||
name, mode, strerror (errno));
|
||||
return;
|
||||
}
|
||||
fd = fileno (fp);
|
||||
fd = es_fileno (fp);
|
||||
|
||||
if (opt.verbose)
|
||||
log_error ("file '%s' opened in \"%s\" mode, fd=%d\n",
|
||||
|
@ -916,7 +916,7 @@ do_sendfd (assuan_context_t ctx, char *line)
|
|||
rc = assuan_sendfd (ctx, INT2FD (fd) );
|
||||
if (rc)
|
||||
log_error ("sending descriptor %d failed: %s\n", fd, gpg_strerror (rc));
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
}
|
||||
|
||||
|
||||
|
@ -932,7 +932,7 @@ do_recvfd (assuan_context_t ctx, char *line)
|
|||
static void
|
||||
do_open (char *line)
|
||||
{
|
||||
FILE *fp;
|
||||
estream_t fp;
|
||||
char *varname, *name, *mode, *p;
|
||||
int fd;
|
||||
|
||||
|
@ -976,14 +976,14 @@ do_open (char *line)
|
|||
}
|
||||
|
||||
/* Open and send. */
|
||||
fp = fopen (name, mode);
|
||||
fp = es_fopen (name, mode);
|
||||
if (!fp)
|
||||
{
|
||||
log_error ("can't open '%s' in \"%s\" mode: %s\n",
|
||||
name, mode, strerror (errno));
|
||||
return;
|
||||
}
|
||||
fd = dup (fileno (fp));
|
||||
fd = dup (es_fileno (fp));
|
||||
if (fd >= 0 && fd < DIM (open_fd_table))
|
||||
{
|
||||
open_fd_table[fd].inuse = 1;
|
||||
|
@ -1033,7 +1033,7 @@ do_open (char *line)
|
|||
if (fd != -1)
|
||||
close (fd); /* Table was full. */
|
||||
}
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1566,17 +1566,17 @@ main (int argc, char **argv)
|
|||
|
||||
if (current_datasink)
|
||||
{
|
||||
if (current_datasink != stdout)
|
||||
fclose (current_datasink);
|
||||
if (current_datasink != es_stdout)
|
||||
es_fclose (current_datasink);
|
||||
current_datasink = NULL;
|
||||
}
|
||||
tmpline = opt.enable_varsubst? substitute_line (p) : NULL;
|
||||
fname = tmpline? tmpline : p;
|
||||
if (fname && !strcmp (fname, "-"))
|
||||
current_datasink = stdout;
|
||||
current_datasink = es_stdout;
|
||||
else if (fname && *fname)
|
||||
{
|
||||
current_datasink = fopen (fname, "wb");
|
||||
current_datasink = es_fopen (fname, "wb");
|
||||
if (!current_datasink)
|
||||
log_error ("can't open '%s': %s\n",
|
||||
fname, strerror (errno));
|
||||
|
@ -1905,6 +1905,7 @@ handle_inquire (assuan_context_t ctx, char *line)
|
|||
{
|
||||
const char *name;
|
||||
definq_t d;
|
||||
/* FIXME: Due to the use of popen we can't easily switch to estream. */
|
||||
FILE *fp = NULL;
|
||||
char buffer[1024];
|
||||
int rc, n;
|
||||
|
@ -2056,7 +2057,7 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
|
|||
}
|
||||
else
|
||||
c = *s;
|
||||
putc (c, current_datasink);
|
||||
es_putc (c, current_datasink);
|
||||
}
|
||||
}
|
||||
else if (opt.hex)
|
||||
|
@ -2127,7 +2128,7 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
|
|||
{
|
||||
if (need_lf)
|
||||
{
|
||||
if (!current_datasink || current_datasink != stdout)
|
||||
if (!current_datasink || current_datasink != es_stdout)
|
||||
putchar ('\n');
|
||||
need_lf = 0;
|
||||
}
|
||||
|
@ -2136,7 +2137,7 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
|
|||
&& line[0] == 'S'
|
||||
&& (line[1] == '\0' || line[1] == ' '))
|
||||
{
|
||||
if (!current_datasink || current_datasink != stdout)
|
||||
if (!current_datasink || current_datasink != es_stdout)
|
||||
{
|
||||
fwrite (line, linelen, 1, stdout);
|
||||
putchar ('\n');
|
||||
|
@ -2146,7 +2147,7 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
|
|||
&& line[0] == 'O' && line[1] == 'K'
|
||||
&& (line[2] == '\0' || line[2] == ' '))
|
||||
{
|
||||
if (!current_datasink || current_datasink != stdout)
|
||||
if (!current_datasink || current_datasink != es_stdout)
|
||||
{
|
||||
fwrite (line, linelen, 1, stdout);
|
||||
putchar ('\n');
|
||||
|
@ -2164,7 +2165,7 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
|
|||
if (!errval)
|
||||
errval = -1;
|
||||
set_int_var ("?", errval);
|
||||
if (!current_datasink || current_datasink != stdout)
|
||||
if (!current_datasink || current_datasink != es_stdout)
|
||||
{
|
||||
fwrite (line, linelen, 1, stdout);
|
||||
putchar ('\n');
|
||||
|
@ -2178,7 +2179,7 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
|
|||
&& line[6] == 'E'
|
||||
&& (line[7] == '\0' || line[7] == ' '))
|
||||
{
|
||||
if (!current_datasink || current_datasink != stdout)
|
||||
if (!current_datasink || current_datasink != es_stdout)
|
||||
{
|
||||
fwrite (line, linelen, 1, stdout);
|
||||
putchar ('\n');
|
||||
|
@ -2190,7 +2191,7 @@ read_and_print_response (assuan_context_t ctx, int withhash, int *r_goterr)
|
|||
&& line[0] == 'E' && line[1] == 'N' && line[2] == 'D'
|
||||
&& (line[3] == '\0' || line[3] == ' '))
|
||||
{
|
||||
if (!current_datasink || current_datasink != stdout)
|
||||
if (!current_datasink || current_datasink != es_stdout)
|
||||
{
|
||||
fwrite (line, linelen, 1, stdout);
|
||||
putchar ('\n');
|
||||
|
|
|
@ -912,7 +912,7 @@ ensure_policy_file (const char *addrspec)
|
|||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
if (gpg_err_code (err) == GPG_ERR_EEXIST)
|
||||
err = 0; /* Was created between the access() and fopen(). */
|
||||
err = 0; /* Was created between the gnupg_access() and es_fopen(). */
|
||||
else
|
||||
log_error ("domain %s: error creating '%s': %s\n",
|
||||
domain, fname, gpg_strerror (err));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue