diff options
Diffstat (limited to '')
-rw-r--r-- | g10/openfile.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/g10/openfile.c b/g10/openfile.c index e60520adb..af0ab3c1d 100644 --- a/g10/openfile.c +++ b/g10/openfile.c @@ -71,6 +71,36 @@ overwrite_filep( const char *fname ) /**************** + * Strip know extensions from iname and return a newly allocated + * filename. Return NULL if we can't do that. + */ +char * +make_outfile_name( const char *iname ) +{ + size_t n; + + if( (!iname || (*iname=='-' && !iname[1]) )) + return m_strdup("-"); + + #ifdef HAVE_DRIVE_LETTERS + #warning add case insensitive compare + #endif + n = strlen(iname); + if( n > 4 && ( !strcmp(iname+n-4,".gpg") + || !strcmp(iname+n-4,".sig") + || !strcmp(iname+n-4,".asc") ) ) { + char *buf = m_strdup( iname ); + buf[n-4] = 0; + return buf; + } + + log_error(_("%s: unknown suffix\n"), iname ); + return NULL; +} + + + +/**************** * Make an output filename for the inputfile INAME. * Returns an IOBUF and an errorcode * Mode 0 = use ".gpg" @@ -108,6 +138,7 @@ open_outfile( const char *iname, int mode, IOBUF *a ) mode==2 ? ".sig" : ".gpg"); name = buf; } + if( overwrite_filep( name ) ) { if( !(*a = iobuf_create( name )) ) { log_error(_("%s: can't create: %s\n"), name, strerror(errno) ); @@ -124,6 +155,7 @@ open_outfile( const char *iname, int mode, IOBUF *a ) } + /**************** * Try to open a file without the extension ".sig" or ".asc" * Return NULL if such a file is not available. |