mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
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 <wk@gnupg.org>
This commit is contained in:
parent
52385a2ba1
commit
60b4982836
7 changed files with 52 additions and 70 deletions
|
@ -1,7 +1,7 @@
|
|||
/* sysutils.c - system helpers
|
||||
* Copyright (C) 1991-2001, 2003-2004,
|
||||
* 2006-2008 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2013-2014 Werner Koch
|
||||
* Copyright (C) 2013-2016 Werner Koch
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -83,6 +83,10 @@
|
|||
|
||||
#define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A'))
|
||||
|
||||
/* Flag to tell whether special file names are enabled. See gpg.c for
|
||||
* an explanation of these file names. */
|
||||
static int allow_special_filenames;
|
||||
|
||||
|
||||
static GPGRT_INLINE gpg_error_t
|
||||
my_error_from_syserror (void)
|
||||
|
@ -168,6 +172,13 @@ enable_core_dumps (void)
|
|||
}
|
||||
|
||||
|
||||
/* Allow the use of special "-&nnn" style file names. */
|
||||
void
|
||||
enable_special_filenames (void)
|
||||
{
|
||||
allow_special_filenames = 1;
|
||||
}
|
||||
|
||||
|
||||
/* Return a string which is used as a kind of process ID. */
|
||||
const byte *
|
||||
|
@ -402,6 +413,29 @@ translate_sys2libc_fd_int (int fd, int for_write)
|
|||
}
|
||||
|
||||
|
||||
/* Check whether FNAME has the form "-&nnnn", where N is a non-zero
|
||||
* number. Returns this number or -1 if it is not the case. If the
|
||||
* caller wants to use the file descriptor for writing FOR_WRITE shall
|
||||
* be set to 1. If NOTRANSLATE is set the Windows spefic mapping is
|
||||
* not done. */
|
||||
int
|
||||
check_special_filename (const char *fname, int for_write, int notranslate)
|
||||
{
|
||||
if (allow_special_filenames
|
||||
&& fname && *fname == '-' && fname[1] == '&')
|
||||
{
|
||||
int i;
|
||||
|
||||
fname += 2;
|
||||
for (i=0; digitp (fname+i); i++ )
|
||||
;
|
||||
if (!fname[i])
|
||||
return notranslate? atoi (fname)
|
||||
/**/ : translate_sys2libc_fd_int (atoi (fname), for_write);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* Replacement for tmpfile(). This is required because the tmpfile
|
||||
function of Windows' runtime library is broken, insecure, ignores
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue