X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxmisc.c;h=4c6a76707d1f77484d975d39f272c953e74932fe;hb=90e7bf4228fa74fda1c65cb2597c9d964329f702;hp=c613a204f5b779714f9cac13314676b01c09c00f;hpb=d0beed9aba20865b9829e3203b4067e8822a0f4d;p=PuTTY.git diff --git a/unix/uxmisc.c b/unix/uxmisc.c index c613a204..4c6a7670 100644 --- a/unix/uxmisc.c +++ b/unix/uxmisc.c @@ -2,8 +2,10 @@ * PuTTY miscellaneous Unix stuff */ +#include #include #include +#include #include #include #include @@ -121,3 +123,29 @@ void pgp_fingerprints(void) "PuTTY Master Key (DSA), 1024-bit:\n" " " PGP_DSA_MASTER_KEY_FP "\n", stdout); } + +/* + * Set FD_CLOEXEC on a file descriptor + */ +int cloexec(int fd) { + int fdflags; + + fdflags = fcntl(fd, F_GETFD); + if (fdflags == -1) return -1; + return fcntl(fd, F_SETFD, fdflags | FD_CLOEXEC); +} + +FILE *f_open(struct Filename filename, char const *mode, int is_private) +{ + if (!is_private) { + return fopen(filename.path, mode); + } else { + int fd; + assert(mode[0] == 'w'); /* is_private is meaningless for read */ + fd = open(filename.path, O_WRONLY | O_CREAT | O_TRUNC, + 0700); + if (fd < 0) + return NULL; + return fdopen(fd, mode); + } +}