BSD 4_4_Lite2 release
[unix-history] / usr / src / games / sail / sync.c
index eabbfaa..8f8dc7d 100644 (file)
@@ -1,10 +1,43 @@
+/*
+ * Copyright (c) 1983, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)sync.c      2.7 85/03/04";
-#endif
+static char sccsid[] = "@(#)sync.c     8.2 (Berkeley) 4/28/95";
+#endif /* not lint */
 
 
-#include "externs.h"
 #include <sys/file.h>
 #include <sys/file.h>
-#include <sys/errno.h>
+#include <errno.h>
+#include "extern.h"
 
 #define BUFSIZE 4096
 
 
 #define BUFSIZE 4096
 
@@ -57,19 +90,19 @@ 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;
-       }
-       sync_seek == 0;
+       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;
 }
 
        return 0;
 }
 
@@ -104,15 +137,15 @@ Write(type, ship, isstr, a, b, c, d)
 
 Sync()
 {
 
 Sync()
 {
-       int (*sig1)(), (*sig2)();
+       sig_t sighup, sigint;
        register n;
        int type, shipnum, isstr, a, b, c, d;
        char buf[80];
        char erred = 0;
        extern errno;
 
        register n;
        int type, shipnum, isstr, a, b, c, d;
        char buf[80];
        char erred = 0;
        extern errno;
 
-       sig1 = signal(SIGHUP, SIG_IGN);
-       sig2 = signal(SIGINT, SIG_IGN);
+       sighup = signal(SIGHUP, SIG_IGN);
+       sigint = signal(SIGINT, SIG_IGN);
        for (n = TIMEOUT; --n >= 0;) {
 #ifdef LOCK_EX
                if (flock(fileno(sync_fp), LOCK_EX|LOCK_NB) >= 0)
        for (n = TIMEOUT; --n >= 0;) {
 #ifdef LOCK_EX
                if (flock(fileno(sync_fp), LOCK_EX|LOCK_NB) >= 0)
@@ -174,7 +207,8 @@ bad:
 out:
        if (!erred && sync_bp != sync_buf) {
                (void) fseek(sync_fp, 0L, 2);
 out:
        if (!erred && sync_bp != sync_buf) {
                (void) fseek(sync_fp, 0L, 2);
-               (void) fputs(sync_buf, sync_fp);
+               (void) fwrite(sync_buf, sizeof *sync_buf, sync_bp - sync_buf,
+                       sync_fp);
                (void) fflush(sync_fp);
                sync_bp = sync_buf;
        }
                (void) fflush(sync_fp);
                sync_bp = sync_buf;
        }
@@ -184,8 +218,8 @@ out:
 #else
        (void) unlink(sync_lock);
 #endif
 #else
        (void) unlink(sync_lock);
 #endif
-       (void) signal(SIGHUP, sig1);
-       (void) signal(SIGINT, sig2);
+       (void) signal(SIGHUP, sighup);
+       (void) signal(SIGINT, sigint);
        return erred ? -1 : 0;
 }
 
        return erred ? -1 : 0;
 }
 
@@ -253,7 +287,10 @@ sync_update(type, ship, a, b, c, d)
                }
        case W_SIGNAL:
                if (mode == MODE_PLAYER)
                }
        case W_SIGNAL:
                if (mode == MODE_PLAYER)
-                       Signal("\7%s (%c%c): %s", ship, a);
+                       if (nobells)
+                               Signal("%s (%c%c): %s", ship, a);
+                       else
+                               Signal("\7%s (%c%c): %s", ship, a);
                break;
        case W_CREW: {
                register struct shipspecs *s = ship->specs;
                break;
        case W_CREW: {
                register struct shipspecs *s = ship->specs;