=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/yacc/main.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/yacc/main.c 1996/04/21 23:45:13 1.3 +++ src/usr.bin/yacc/main.c 1996/06/25 01:54:55 1.4 @@ -50,6 +50,9 @@ #endif #endif /* not lint */ +#include +#include +#include #include #include "defs.h" @@ -111,10 +114,6 @@ short **derives; char *nullable; -extern char *mktemp(); -extern char *getenv(); - - done(k) int k; { @@ -386,8 +385,29 @@ } +FILE * +fsopen(name, mode) + char *name; + char *mode; +{ + FILE *fp = NULL; + int fd, mod = O_RDONLY; + + if (strchr(mode, 'w')) + mod = O_RDWR; + if ((fd = open(name, mod | O_EXCL|O_CREAT, 0666)) == -1 || + (fp = fdopen(fd, mode)) == NULL) { + if (fd != -1) + close(fd); + } + return (fp); +} + + open_files() { + int fd; + create_file_names(); if (input_file == 0) @@ -397,11 +417,11 @@ open_error(input_file_name); } - action_file = fopen(action_file_name, "w"); + action_file = fsopen(action_file_name, "w"); if (action_file == 0) open_error(action_file_name); - text_file = fopen(text_file_name, "w"); + text_file = fsopen(text_file_name, "w"); if (text_file == 0) open_error(text_file_name); @@ -417,7 +437,7 @@ defines_file = fopen(defines_file_name, "w"); if (defines_file == 0) open_error(defines_file_name); - union_file = fopen(union_file_name, "w"); + union_file = fsopen(union_file_name, "w"); if (union_file == 0) open_error(union_file_name); }