From 60b4982836a00ef6b2a97d16f735b3f6b74dce62 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 29 Nov 2016 16:18:24 +0100 Subject: gpg,sm: Merge the two versions of check_special_filename. * sm/gpgsm.c (check_special_filename): Move to .. * common/sysutils.c (check_special_filename): here. Add arg NOTRANSLATE. (allow_special_filenames): New local var. (enable_special_filenames): New public functions. * sm/gpgsm.c (allow_special_filenames): Remove var. (main): Call enable_special_filenames instead of setting the var. (open_read, open_es_fread, open_es_fwrite): Call check_special_filename with 0 for NOTRANSLATE. * common/iobuf.c (special_names_enabled): Remove var. (iobuf_enable_special_filenames): Remove func. (check_special_filename): Remove func. (iobuf_is_pipe_filename): Call new version of the function with NOTRANSLATE set. (do_open): Ditto. * g10/gpg.c (main): Call enable_special_filenames instead of iobuf_enable_special_filenames. * g10/gpgv.c (main): Ditto. -- Note that we keep the iobuf.c:translate_file_handle because it is a bit different (for whatever reasons) than the translate function from sysutils. Signed-off-by: Werner Koch --- common/iobuf.c | 37 ++++--------------------------------- 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'common/iobuf.c') diff --git a/common/iobuf.c b/common/iobuf.c index ed90bd7a2..d346027e4 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -155,11 +155,6 @@ typedef struct block_filter_ctx_t; -/* Global flag to tell whether special file names are enabled. See - gpg.c for an explanation of these file names. FIXME: This does not - belong in the iobuf subsystem. */ -static int special_names_enabled; - /* Local prototypes. */ static int underflow (iobuf_t a, int clear_pending_eof); static int underflow_target (iobuf_t a, int clear_pending_eof, size_t target); @@ -1237,41 +1232,16 @@ iobuf_temp_with_content (const char *buffer, size_t length) return a; } -void -iobuf_enable_special_filenames (int yes) -{ - special_names_enabled = yes; -} - - -/* See whether the filename has the form "-&nnnn", where n is a - non-zero number. Returns this number or -1 if it is not the - case. */ -static int -check_special_filename (const char *fname) -{ - if (special_names_enabled && fname && *fname == '-' && fname[1] == '&') - { - int i; - - fname += 2; - for (i = 0; digitp (fname+i); i++) - ; - if (!fname[i]) - return atoi (fname); - } - return -1; -} - int iobuf_is_pipe_filename (const char *fname) { if (!fname || (*fname=='-' && !fname[1]) ) return 1; - return check_special_filename (fname) != -1; + return check_special_filename (fname, 0, 1) != -1; } + static iobuf_t do_open (const char *fname, int special_filenames, int use, const char *opentype, int mode700) @@ -1304,7 +1274,8 @@ do_open (const char *fname, int special_filenames, } else if (!fname) return NULL; - else if (special_filenames && (fd = check_special_filename (fname)) != -1) + else if (special_filenames + && (fd = check_special_filename (fname, 0, 1)) != -1) return iobuf_fdopen (translate_file_handle (fd, use == IOBUF_INPUT ? 0 : 1), opentype); else -- cgit v1.2.3