From 831cd76256290541a102bc660442918c95a65e6c Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 25 Jun 2007 11:54:43 +0000 Subject: Fixed a problem in estream-printf.c. Changes for Windows (gpgsm -k does now work). Minor cleanups. --- common/sysutils.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'common/sysutils.c') diff --git a/common/sysutils.c b/common/sysutils.c index ff1fe1ba4..a3fc8cb07 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -272,3 +272,32 @@ gnupg_sleep (unsigned int seconds) # endif #endif } + + +/* This function is a NOP for POSIX systems but required under Windows + as the file handles as returned by OS calls (like CreateFile) are + different from the libc file descriptors (like open). This function + 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) +{ +#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 (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 fd; +} -- cgit v1.2.3