From d2a70fd8348d6c11d1960caf2afe0701833dad6a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 19 Feb 2015 17:22:27 +0100 Subject: 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 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 --- g10/tdbdump.c | 60 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'g10/tdbdump.c') diff --git a/g10/tdbdump.c b/g10/tdbdump.c index c12e9b7a3..bf9f3875b 100644 --- a/g10/tdbdump.c +++ b/g10/tdbdump.c @@ -78,12 +78,12 @@ list_trustdb( const char *username ) ulong recnum; int i; - printf("TrustDB: %s\n", tdbio_get_dbname() ); + es_printf ("TrustDB: %s\n", tdbio_get_dbname() ); for(i=9+strlen(tdbio_get_dbname()); i > 0; i-- ) - putchar('-'); - putchar('\n'); + es_putc ('-', es_stdout); + es_putc ('\n', es_stdout); for(recnum=0; !tdbio_read_record( recnum, &rec, 0); recnum++ ) - tdbio_dump_record( &rec, stdout ); + tdbio_dump_record (&rec, es_stdout); } } @@ -97,23 +97,25 @@ list_trustdb( const char *username ) void export_ownertrust() { - TRUSTREC rec; - ulong recnum; - int i; - byte *p; + TRUSTREC rec; + ulong recnum; + int i; + byte *p; - init_trustdb(); - printf(_("# List of assigned trustvalues, created %s\n" - "# (Use \"gpg --import-ownertrust\" to restore them)\n"), - asctimestamp( make_timestamp() ) ); - for(recnum=0; !tdbio_read_record( recnum, &rec, 0); recnum++ ) { - if( rec.rectype == RECTYPE_TRUST ) { - if( !rec.r.trust.ownertrust ) - continue; - p = rec.r.trust.fingerprint; - for(i=0; i < 20; i++, p++ ) - printf("%02X", *p ); - printf(":%u:\n", (unsigned int)rec.r.trust.ownertrust ); + init_trustdb(); + es_printf (_("# List of assigned trustvalues, created %s\n" + "# (Use \"gpg --import-ownertrust\" to restore them)\n"), + asctimestamp( make_timestamp() ) ); + for (recnum=0; !tdbio_read_record (recnum, &rec, 0); recnum++ ) + { + if (rec.rectype == RECTYPE_TRUST) + { + if (!rec.r.trust.ownertrust) + continue; + p = rec.r.trust.fingerprint; + for (i=0; i < 20; i++, p++ ) + es_printf("%02X", *p ); + es_printf (":%u:\n", (unsigned int)rec.r.trust.ownertrust ); } } } @@ -122,7 +124,7 @@ export_ownertrust() void import_ownertrust( const char *fname ) { - FILE *fp; + estream_t fp; int is_stdin=0; char line[256]; char *p; @@ -134,24 +136,24 @@ import_ownertrust( const char *fname ) init_trustdb(); if( iobuf_is_pipe_filename (fname) ) { - fp = stdin; + fp = es_stdin; fname = "[stdin]"; is_stdin = 1; } - else if( !(fp = fopen( fname, "r" )) ) { + else if( !(fp = es_fopen( fname, "r" )) ) { log_error ( _("can't open '%s': %s\n"), fname, strerror(errno) ); return; } - if (is_secured_file (fileno (fp))) + if (is_secured_file (es_fileno (fp))) { - fclose (fp); + es_fclose (fp); gpg_err_set_errno (EPERM); log_error (_("can't open '%s': %s\n"), fname, strerror(errno) ); return; } - while( fgets( line, DIM(line)-1, fp ) ) { + while (es_fgets (line, DIM(line)-1, fp)) { TRUSTREC rec; if( !*line || *line == '#' ) @@ -216,10 +218,10 @@ import_ownertrust( const char *fname ) log_error (_("error finding trust record in '%s': %s\n"), fname, gpg_strerror (rc)); } - if( ferror(fp) ) + if (es_ferror (fp)) log_error ( _("read error in '%s': %s\n"), fname, strerror(errno) ); - if( !is_stdin ) - fclose(fp); + if (!is_stdin) + es_fclose (fp); if (any) { -- cgit v1.2.3