diff options
Diffstat (limited to 'FICS/utils.c')
-rw-r--r-- | FICS/utils.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/FICS/utils.c b/FICS/utils.c index cf12871..0e1461a 100644 --- a/FICS/utils.c +++ b/FICS/utils.c @@ -42,12 +42,16 @@ Markus Uhlin 25/07/21 Replaced non-reentrant functions with their corresponding thread safe version. + Markus Uhlin 25/07/28 truncate_file: restricted file + permissions upon creation. */ #include "stdinclude.h" #include "common.h" #include <err.h> +#include <errno.h> +#include <fcntl.h> #include "config.h" #include "network.h" @@ -853,8 +857,17 @@ truncate_file(char *file, int lines) fclose(fp); if (trunc) { - if ((fp = fopen(file, "w")) == NULL) { - warn("%s: fopen", __func__); + int fd; + + errno = 0; + fd = open(file, O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR); + + if (fd < 0) { + warn("%s: open", __func__); + return 1; + } else if ((fp = fdopen(fd, "w")) == NULL) { + warn("%s: fdopen", __func__); + close(fd); return 1; } |