diff options
author | Werner Koch <[email protected]> | 2007-06-25 11:54:43 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2007-06-25 11:54:43 +0000 |
commit | 831cd76256290541a102bc660442918c95a65e6c (patch) | |
tree | c5b54be81f3530fee16f7d6ecf832a235bdba222 /common/sysutils.c | |
parent | Implemented the --gen-key command as we can't use the gpgsm-gencert.sh under ... (diff) | |
download | gnupg-831cd76256290541a102bc660442918c95a65e6c.tar.gz gnupg-831cd76256290541a102bc660442918c95a65e6c.zip |
Fixed a problem in estream-printf.c.
Changes for Windows (gpgsm -k does now work).
Minor cleanups.
Diffstat (limited to 'common/sysutils.c')
-rw-r--r-- | common/sysutils.c | 29 |
1 files changed, 29 insertions, 0 deletions
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; +} |