mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Translate all file descriptors received from assuan.
This commit is contained in:
parent
b188c246ca
commit
5f97dd2c44
9 changed files with 86 additions and 37 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue