diff options
author | Werner Koch <wk@gnupg.org> | 2007-07-12 17:28:30 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2007-07-12 17:28:30 +0200 |
commit | 5f97dd2c44662784d63e62862a38ef7164d8758e (patch) | |
tree | c5db7a48d285d1d67c6b21d97f35f30d2058595e /common | |
parent | Typo fixes. (diff) | |
download | gnupg2-5f97dd2c44662784d63e62862a38ef7164d8758e.tar.xz gnupg2-5f97dd2c44662784d63e62862a38ef7164d8758e.zip |
Translate all file descriptors received from assuan.
Diffstat (limited to 'common')
-rw-r--r-- | common/ChangeLog | 6 | ||||
-rw-r--r-- | common/sysutils.c | 38 | ||||
-rw-r--r-- | common/sysutils.h | 17 |
3 files changed, 47 insertions, 14 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index 3d1f47160..7dd887cdc 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,9 @@ +2007-07-12 Werner Koch <wk@g10code.com> + + * sysutils.h (gnupg_fd_t): New. + * sysutils.c (translate_sys2libc_fd): Use that type instead of int. + (translate_sys2libc_fd_int): New. + 2007-07-09 Werner Koch <wk@g10code.com> * t-gettime.c (test_isotime2epoch): Use time_t and not u32. diff --git a/common/sysutils.c b/common/sysutils.c index 47031a152..6f6a9cbf4 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -278,24 +278,36 @@ gnupg_sleep (unsigned int seconds) translates system file handles to libc file handles. FOR_WRITE gives the direction of the handle. */ int -translate_sys2libc_fd (int fd, int for_write) +translate_sys2libc_fd (gnupg_fd_t fd, int for_write) { #ifdef HAVE_W32_SYSTEM int x; - - if (fd <= 2) - return fd; /* Do not do this for error, stdin, stdout, stderr. - (This also ignores an fd of -1.) */ - x = _open_osfhandle (fd, for_write ? 1 : 0); + if (fd == GNUPG_INVALID_FD) + return -1; + + /* Note that _open_osfhandle is currently defined to take and return + a long. */ + x = _open_osfhandle ((long)fd, for_write ? 1 : 0); if (x == -1) log_error ("failed to translate osfhandle %p\n", (void *) fd); - else - { -/* log_info ("_open_osfhandle %p yields %d%s\n", */ -/* (void*)fd, x, for_write? " for writing":"" ); */ - fd = x; - } -#endif /* HAVE_W32_SYSTEM */ + return x; +#else /*!HAVE_W32_SYSTEM */ return fd; +#endif +} + +/* This is the same as translate_sys2libc_fd but takes an integer + which is assumet to be such an system handle. */ +int +translate_sys2libc_fd_int (int fd, int for_write) +{ +#ifdef HAVE_W32_SYSTEM + if (fd <= 2) + return fd; /* Do not do this for error, stdin, stdout, stderr. */ + + return translate_sys2libc_fd ((void*)fd, for_write); +#else + return fd; +#endif } diff --git a/common/sysutils.h b/common/sysutils.h index cc7a50d03..42bf58b9c 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -20,13 +20,28 @@ #ifndef GNUPG_COMMON_SYSUTILS_H #define GNUPG_COMMON_SYSUTILS_H +/* Because we use system handles and not libc low level file + descriptors on W32, we need to declare them as HANDLE (which + actually is a plain pointer). This is required to eventually + support 64 bits Windows systems. */ +#ifdef HAVE_W32_SYSTEM +typedef void *gnupg_fd_t; +#define GNUPG_INVALID_FD ((void*)(-1)) +#else +typedef int gnupg_fd_t; +#define GNUPG_INVALID_FD (-1) +#endif + + void trap_unaligned (void); int disable_core_dumps (void); int enable_core_dumps (void); const unsigned char *get_session_marker (size_t *rlen); /*int check_permissions (const char *path,int extension,int checkonly);*/ void gnupg_sleep (unsigned int seconds); -int translate_sys2libc_fd (int fd, int for_write); +int translate_sys2libc_fd (gnupg_fd_t fd, int for_write); +int translate_sys2libc_fd_int (int fd, int for_write); + #ifdef HAVE_W32_SYSTEM |