diff options
author | Werner Koch <wk@gnupg.org> | 1999-06-01 16:08:57 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1999-06-01 16:08:57 +0200 |
commit | 3dddf602dd95863dab344486534874b4b561bd3d (patch) | |
tree | 322e4f944eb596a22af9fc4d98f2f000117672a7 /g10/openfile.c | |
parent | See ChangeLog: Mon May 31 19:41:10 CEST 1999 Werner Koch (diff) | |
download | gnupg2-3dddf602dd95863dab344486534874b4b561bd3d.tar.xz gnupg2-3dddf602dd95863dab344486534874b4b561bd3d.zip |
See ChangeLog: Tue Jun 1 16:01:46 CEST 1999 Werner Koch
Diffstat (limited to 'g10/openfile.c')
-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. |