intuit the appropriate DEV_BSIZE from fsbtodb macro
[unix-history] / usr / src / usr.bin / sccs / sccs.c
index c5ac5fa..f1d2707 100644 (file)
@@ -1,7 +1,23 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)sccs.c     5.2 (Berkeley) %G%";
+#endif not lint
+
 # include <stdio.h>
 # include <sys/param.h>
 # include <sys/stat.h>
 # include <stdio.h>
 # include <sys/param.h>
 # include <sys/stat.h>
-# include <dir.h>
+# include <sys/dir.h>
 # include <errno.h>
 # include <signal.h>
 # include <sysexits.h>
 # include <errno.h>
 # include <signal.h>
 # include <sysexits.h>
 **             Copyright 1980 Regents of the University of California
 */
 
 **             Copyright 1980 Regents of the University of California
 */
 
-static char SccsId[] = "@(#)sccs.c     1.68 %G%";
 \f
 /*******************  Configuration Information  ********************/
 
 \f
 /*******************  Configuration Information  ********************/
 
@@ -234,7 +249,7 @@ main(argc, argv)
        char buf[FBUFSIZ];
 
        /* pull "SccsDir" out of the environment (possibly) */
        char buf[FBUFSIZ];
 
        /* pull "SccsDir" out of the environment (possibly) */
-       p = getenv("PROJECT");
+       p = getenv("PROJECTDIR");
        if (p != NULL && p[0] != '\0')
        {
                if (p[0] == '/')
        if (p != NULL && p[0] != '\0')
        {
                if (p[0] == '/')
@@ -883,7 +898,7 @@ clean(mode, argv)
        struct direct *dir;
        char buf[FBUFSIZ];
        char *bufend;
        struct direct *dir;
        char buf[FBUFSIZ];
        char *bufend;
-       register DIR *dirfd;
+       register DIR *dirp;
        register char *basefile;
        bool gotedit;
        bool gotpfent;
        register char *basefile;
        bool gotedit;
        bool gotpfent;
@@ -947,8 +962,8 @@ clean(mode, argv)
        gstrcat(buf, SccsPath, sizeof(buf));
        bufend = &buf[strlen(buf)];
 
        gstrcat(buf, SccsPath, sizeof(buf));
        bufend = &buf[strlen(buf)];
 
-       dirfd = opendir(buf);
-       if (dirfd == NULL)
+       dirp = opendir(buf);
+       if (dirp == NULL)
        {
                usrerr("cannot open %s", buf);
                return (EX_NOINPUT);
        {
                usrerr("cannot open %s", buf);
                return (EX_NOINPUT);
@@ -961,7 +976,7 @@ clean(mode, argv)
        */
 
        gotedit = FALSE;
        */
 
        gotedit = FALSE;
-       while (dir = readdir(dirfd)) {
+       while (dir = readdir(dirp)) {
                if (strncmp(dir->d_name, "s.", 2) != 0)
                        continue;
                
                if (strncmp(dir->d_name, "s.", 2) != 0)
                        continue;
                
@@ -1010,7 +1025,7 @@ clean(mode, argv)
        }
 
        /* cleanup & report results */
        }
 
        /* cleanup & report results */
-       closedir(dirfd);
+       closedir(dirp);
        if (!gotedit && mode == INFOC)
        {
                printf("Nothing being edited");
        if (!gotedit && mode == INFOC)
        {
                printf("Nothing being edited");
@@ -1081,7 +1096,7 @@ unedit(fn)
        char *fn;
 {
        register FILE *pfp;
        char *fn;
 {
        register FILE *pfp;
-       char *pfn;
+       char *cp, *pfn;
        static char tfn[] = "/tmp/sccsXXXXX";
        FILE *tfp;
        register char *q;
        static char tfn[] = "/tmp/sccsXXXXX";
        FILE *tfp;
        register char *q;
@@ -1148,6 +1163,32 @@ unedit(fn)
                }
        }
 
                }
        }
 
+       /*
+        * Before changing anything, make sure we can remove
+        * the file in question (assuming it exists).
+        */
+       if (delete) {
+               extern int errno;
+
+               cp = tail(fn);
+               errno = 0;
+               if (access(cp, 0) < 0 && errno != ENOENT)
+                       goto bad;
+               if (errno == 0)
+                       /*
+                        * This is wrong, but the rest of the program
+                        * has built in assumptions about "." as well,
+                        * so why make unedit a special case?
+                        */
+                       if (access(".", 2) < 0) {
+       bad:
+                               printf("%12s: can't remove\n", cp);
+                               fclose(tfp);
+                               fclose(pfp);
+                               unlink(tfn);
+                               return (FALSE);
+                       }
+       }
        /* do final cleanup */
        if (others)
        {
        /* do final cleanup */
        if (others)
        {
@@ -1177,8 +1218,13 @@ unedit(fn)
        /* actually remove the g-file */
        if (delete)
        {
        /* actually remove the g-file */
        if (delete)
        {
-               unlink(tail(fn));
-               printf("%12s: removed\n", tail(fn));
+               /*
+                * Since we've checked above, we can
+                * use the return from unlink to
+                * determine if the file existed or not.
+                */
+               if (unlink(cp) >= 0)
+                       printf("%12s: removed\n", cp);
                return (TRUE);
        }
        else
                return (TRUE);
        }
        else