Commit Diff


commit - 73dbfcd1e2022b9522813cf0cdf80495da6f5ee7
commit + d5d694114aefd691c053ca794ef139e4bc80b679
blob - 785d1a13d0a80df4013cee678dee478a74666cbd
blob + 24cdcd76a5b7afb32e0c7ca260c29238ff24db97
--- FICS/utils.c
+++ FICS/utils.c
@@ -855,9 +855,18 @@ 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;
 		}
 
 		for (i = 0; i < lines; i++) {