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>
This commit is contained in:
parent
c94ee1386e
commit
390497ea11
23 changed files with 220 additions and 216 deletions
|
@ -182,7 +182,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
|
||||
|
@ -892,7 +892,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;
|
||||
|
||||
|
@ -918,14 +918,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",
|
||||
|
@ -934,7 +934,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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -950,7 +950,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;
|
||||
|
||||
|
@ -994,14 +994,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;
|
||||
|
@ -1051,7 +1051,7 @@ do_open (char *line)
|
|||
if (fd != -1)
|
||||
close (fd); /* Table was full. */
|
||||
}
|
||||
fclose (fp);
|
||||
es_fclose (fp);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1605,17 +1605,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));
|
||||
|
@ -1964,6 +1964,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;
|
||||
|
@ -2115,7 +2116,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)
|
||||
|
@ -2186,7 +2187,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;
|
||||
}
|
||||
|
@ -2195,7 +2196,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');
|
||||
|
@ -2205,7 +2206,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');
|
||||
|
@ -2223,7 +2224,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');
|
||||
|
@ -2237,7 +2238,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');
|
||||
|
@ -2249,7 +2250,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');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue