diff options
author | Werner Koch <[email protected]> | 2015-02-19 16:22:27 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-02-19 16:22:27 +0000 |
commit | d2a70fd8348d6c11d1960caf2afe0701833dad6a (patch) | |
tree | 572a1d61a1571d2d87b37186331352312efff4b8 /g10/gpg.c | |
parent | gpg: Fix segv due to NULL value stored as opaque MPI. (diff) | |
download | gnupg-d2a70fd8348d6c11d1960caf2afe0701833dad6a.tar.gz gnupg-d2a70fd8348d6c11d1960caf2afe0701833dad6a.zip |
gpg: Replace remaining uses of stdio by estream.
* g10/sign.c (sign_file): Use log_printf instead of stderr.
* g10/tdbdump.c (export_ownertrust): Use estream fucntions.
(import_ownertrust): Ditto.
* g10/tdbio.c (tdbio_dump_record): Ditto. Change arg to estream_t.
--
Reported-by: Guilhem Moulin <[email protected]>
Needed for unattended key edits with --status-fd, because since 2.1
status prompts are preceded by es_fflush (in cpr.c:do_get_from_fd)
not fflush(3), so the standard output may not be flushed before each
prompt. (Which breaks scripts using select(2) to multiplex between
the standard and status outputs.)
His patch only affected print_and_check_one_sig_colon() but there are
many more places where stdio and estream are mixed. This patch now
replaces most of them in g10/. At some places stdio is still used,
but that is local to a function and should not have side effects.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/gpg.c')
-rw-r--r-- | g10/gpg.c | 42 |
1 files changed, 20 insertions, 22 deletions
@@ -1038,7 +1038,7 @@ build_list (const char *text, char letter, static void wrong_args( const char *text) { - fprintf (stderr, _("usage: %s [options] %s\n"), GPG_NAME, text); + es_fprintf (es_stderr, _("usage: %s [options] %s\n"), GPG_NAME, text); g10_exit(2); } @@ -4021,7 +4021,7 @@ main (int argc, char **argv) mpi_print (es_stdout, generate_elg_prime( 1, atoi(argv[1]), atoi(argv[2]), NULL,&factors ), 1); - putchar('\n'); + es_putc ('\n', es_stdout); mpi_print (es_stdout, factors[0], 1 ); /* print q */ } else if( mode == 4 && argc == 3 ) { @@ -4029,13 +4029,13 @@ main (int argc, char **argv) mpi_print (es_stdout, generate_elg_prime( 0, atoi(argv[1]), atoi(argv[2]), g, NULL ), 1); - putchar('\n'); + es_putc ('\n', es_stdout); mpi_print (es_stdout, g, 1 ); mpi_free (g); } else wrong_args("--gen-prime mode bits [qbits] "); - putchar('\n'); + es_putc ('\n', es_stdout); } #endif wrong_args("--gen-prime not yet supported "); @@ -4064,21 +4064,21 @@ main (int argc, char **argv) #endif if (opt.armor) { char *tmp = make_radix64_string (p, n); - fputs (tmp, stdout); + es_fputs (tmp, es_stdout); xfree (tmp); if (n%3 == 1) - putchar ('='); + es_putc ('=', es_stdout); if (n%3) - putchar ('='); + es_putc ('=', es_stdout); } else { - fwrite( p, n, 1, stdout ); + es_fwrite( p, n, 1, es_stdout ); } xfree(p); if( !endless ) count -= n; } if (opt.armor) - putchar ('\n'); + es_putc ('\n', es_stdout); } break; @@ -4298,7 +4298,7 @@ print_hex (gcry_md_hd_t md, int algo, const char *fname) if (indent>40) { - printf("\n"); + es_printf ("\n"); indent=0; } @@ -4396,24 +4396,22 @@ print_hashline( gcry_md_hd_t md, int algo, const char *fname ) static void print_mds( const char *fname, int algo ) { - FILE *fp; + estream_t fp; char buf[1024]; size_t n; gcry_md_hd_t md; if (!fname) { - fp = stdin; -#ifdef HAVE_DOSISH_SYSTEM - setmode ( fileno(fp) , O_BINARY ); -#endif + fp = es_stdin; + es_set_binary (fp); } else { - fp = fopen (fname, "rb" ); - if (fp && is_secured_file (fileno (fp))) + fp = es_fopen (fname, "rb" ); + if (fp && is_secured_file (es_fileno (fp))) { - fclose (fp); + es_fclose (fp); fp = NULL; gpg_err_set_errno (EPERM); } @@ -4444,10 +4442,10 @@ print_mds( const char *fname, int algo ) gcry_md_enable (md, GCRY_MD_SHA512); } - while ((n=fread (buf, 1, DIM(buf), fp))) + while ((n=es_fread (buf, 1, DIM(buf), fp))) gcry_md_write (md, buf, n); - if (ferror(fp)) + if (es_ferror(fp)) log_error ("%s: %s\n", fname?fname:"[stdin]", strerror(errno)); else { @@ -4497,8 +4495,8 @@ print_mds( const char *fname, int algo ) } gcry_md_close (md); - if (fp != stdin) - fclose (fp); + if (fp != es_stdin) + es_fclose (fp); } |