don't rely on duped file descriptor
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Sat, 6 Apr 1985 15:02:19 +0000 (07:02 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Sat, 6 Apr 1985 15:02:19 +0000 (07:02 -0800)
SCCS-vsn: games/sail/sync.c 2.8

usr/src/games/sail/sync.c

index eabbfaa..011a321 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)sync.c      2.7 85/03/04";
+static char *sccsid = "@(#)sync.c      2.8 85/04/06";
 #endif
 
 #include "externs.h"
 #endif
 
 #include "externs.h"
@@ -57,18 +57,18 @@ sync_exists(game)
 
 sync_open()
 {
 
 sync_open()
 {
-       if (sync_fp == NULL) {
-               (void) sprintf(sync_lock, LF, game);
-               (void) sprintf(sync_file, SF, game);
-               if (access(sync_file, 0) < 0) {
-                       int omask = umask(issetuid ? 077 : 011);
-                       sync_fp = fopen(sync_file, "w+");
-                       (void) umask(omask);
-               } else
-                       sync_fp = fopen(sync_file, "r+");
-               if (sync_fp == NULL)
-                       return -1;
-       }
+       if (sync_fp != NULL)
+               (void) fclose(sync_fp);
+       (void) sprintf(sync_lock, LF, game);
+       (void) sprintf(sync_file, SF, game);
+       if (access(sync_file, 0) < 0) {
+               int omask = umask(issetuid ? 077 : 011);
+               sync_fp = fopen(sync_file, "w+");
+               (void) umask(omask);
+       } else
+               sync_fp = fopen(sync_file, "r+");
+       if (sync_fp == NULL)
+               return -1;
        sync_seek == 0;
        return 0;
 }
        sync_seek == 0;
        return 0;
 }