diff options
author | Werner Koch <[email protected]> | 1998-07-14 17:10:28 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1998-07-14 17:10:28 +0000 |
commit | 0a76a4465be37c29de4459096e89f9f8b9964cf7 (patch) | |
tree | 5fb00ca21525cb2d9ffbfd81312596a80925403b /g10/plaintext.c | |
parent | fixed types, added new translations. (diff) | |
download | gnupg-0a76a4465be37c29de4459096e89f9f8b9964cf7.tar.gz gnupg-0a76a4465be37c29de4459096e89f9f8b9964cf7.zip |
sync
Diffstat (limited to 'g10/plaintext.c')
-rw-r--r-- | g10/plaintext.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/g10/plaintext.c b/g10/plaintext.c index 8d7b2a97e..1a22ecdbd 100644 --- a/g10/plaintext.c +++ b/g10/plaintext.c @@ -109,14 +109,17 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx, /* no filename or "-" given; write to stdout */ fp = stdout; } - else if( overwrite_filep( fname ) ) + else if( (rc=overwrite_filep( fname )) ) { + if( rc == -1 ) + rc = G10ERR_CREATE_FILE; goto leave; + } if( fp || nooutput ) ; else if( !(fp = fopen(fname,"wb")) ) { log_error("Error creating '%s': %s\n", fname, strerror(errno) ); - rc = G10ERR_WRITE_FILE; + rc = G10ERR_CREATE_FILE; goto leave; } @@ -245,20 +248,43 @@ ask_for_detached_datafile( md_filter_context_t *mfx, const char *inname ) } +static void +do_hash( MD_HANDLE md, IOBUF fp, int textmode ) +{ + text_filter_context_t tfx; + int c; + + if( textmode ) { + memset( &tfx, 0, sizeof tfx); + iobuf_push_filter( fp, text_filter, &tfx ); + } + while( (c = iobuf_get(fp)) != -1 ) + md_putc(md, c ); +} + + /**************** * Hash the given files and append the hash to hash context md. * If FILES is NULL, hash stdin. */ int -hash_datafiles( MD_HANDLE md, STRLIST files, int textmode ) +hash_datafiles( MD_HANDLE md, STRLIST files, + const char *sigfilename, int textmode ) { IOBUF fp; STRLIST sl=NULL; - text_filter_context_t tfx; - int c; - if( !files ) + if( !files ) { + /* check whether we can opne the signed material */ + fp = open_sigfile( sigfilename ); + if( fp ) { + do_hash( md, fp, textmode ); + iobuf_close(fp); + return 0; + } + /* no we can't (no sigfile) - read signed stuff from stdin */ add_to_strlist( &sl, "-"); + } else sl = files; @@ -271,12 +297,7 @@ hash_datafiles( MD_HANDLE md, STRLIST files, int textmode ) free_strlist(sl); return G10ERR_OPEN_FILE; } - if( textmode ) { - memset( &tfx, 0, sizeof tfx); - iobuf_push_filter( fp, text_filter, &tfx ); - } - while( (c = iobuf_get(fp)) != -1 ) - md_putc(md, c ); + do_hash( md, fp, textmode ); iobuf_close(fp); } |