X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/db9b7dcedb001b942ad945a56b2d7bf9b77d7a6a..3ab798412da7dbfc26af43a06e92c13a7b9abf43:/unix/uxmisc.c diff --git a/unix/uxmisc.c b/unix/uxmisc.c index 74eb1568..dd04e6f5 100644 --- a/unix/uxmisc.c +++ b/unix/uxmisc.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -133,3 +134,19 @@ int cloexec(int fd) { 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, + and tricky for append */ + fd = open(filename.path, O_WRONLY | O_CREAT | O_TRUNC, + 0700); + if (fd < 0) + return NULL; + return fdopen(fd, mode); + } +}