summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/util.c b/util.c
index 46c6033313..45c33507bd 100644
--- a/util.c
+++ b/util.c
@@ -234,22 +234,18 @@ valid_filename(char *s)
int fd;
/*
- // if the file exists, then it's a valid filename!
- */
-
- if (_access(s, 0) == 0) {
- return 1;
- }
-
- /*
// It doesn't exist, so see if we can open it.
*/
- if ((fd = _open(s, O_CREAT, 0666)) >= 0) {
+ if ((fd = _open(s, O_CREAT|O_EXCL, 0666)) >= 0) {
_close(fd);
_unlink(s); /* don't leave it laying around */
return 1;
}
+ else if (errno == EEXIST) {
+ /* if the file exists, then it's a valid filename! */
+ return 1;
+ }
return 0;
}
#endif