aboutsummaryrefslogtreecommitdiffstats
path: root/common/sysutils.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2007-07-12 15:28:30 +0000
committerWerner Koch <[email protected]>2007-07-12 15:28:30 +0000
commit5f97dd2c44662784d63e62862a38ef7164d8758e (patch)
treec5db7a48d285d1d67c6b21d97f35f30d2058595e /common/sysutils.c
parentTypo fixes. (diff)
downloadgnupg-5f97dd2c44662784d63e62862a38ef7164d8758e.tar.gz
gnupg-5f97dd2c44662784d63e62862a38ef7164d8758e.zip
Translate all file descriptors received from assuan.
Diffstat (limited to 'common/sysutils.c')
-rw-r--r--common/sysutils.c38
1 files changed, 25 insertions, 13 deletions
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
}