Annotations will always be done inplace from now on.
[mmh] / uip / annosbr.c
index 034aa12..99422e6 100644 (file)
@@ -17,7 +17,7 @@
 /*
 ** static prototypes
 */
-static int annosbr(int, char *, char *, char *, int, int, int, int);
+static int annosbr(int, char *, char *, char *, int, int, int);
 
 /*
 ** This "local" global and the annopreserve() function are a hack that
@@ -29,7 +29,7 @@ static int annosbr(int, char *, char *, char *, int, int, int, int);
 static int preserve_actime_and_modtime = 0;
 
 int
-annotate(char *file, char *comp, char *text, int inplace, int datesw,
+annotate(char *file, char *comp, char *text, int datesw,
        int delete, int append)
 {
        int i, fd;
@@ -39,12 +39,12 @@ annotate(char *file, char *comp, char *text, int inplace, int datesw,
        /* open and lock the file to be annotated */
        if ((fd = lkopen(file, O_RDWR, 0)) == NOTOK) {
                switch (errno) {
-                       case ENOENT:
-                               break;
+               case ENOENT:
+                       break;
 
-                       default:
-                               admonish(file, "unable to lock and open");
-                               break;
+               default:
+                       admonish(file, "unable to lock and open");
+                       break;
                }
                return 1;
        }
@@ -57,7 +57,7 @@ annotate(char *file, char *comp, char *text, int inplace, int datesw,
        b.actime = s.st_atime;
        b.modtime = s.st_mtime;
 
-       i = annosbr(fd, file, comp, text, inplace, datesw, delete, append);
+       i = annosbr(fd, file, comp, text, datesw, delete, append);
 
        if (preserve_actime_and_modtime && utime(file, &b) == -1)
                advise("can't set access and modification times for %s", file);
@@ -135,7 +135,7 @@ annolist(char *file, char *comp, char *text, int number)
                        if (number)
                                printf("%d\t", ++count);
 
-                       if (text == (char *)0 && (sp = strrchr(cp, '/')) != (char *)0)
+                       if (text == NULL && (sp = strrchr(cp, '/')) != NULL)
                                cp = sp + 1;
 
                        printf("%s\n", cp);
@@ -162,12 +162,12 @@ annopreserve(int preserve)
 }
 
 static int
-annosbr(int fd, char *file, char *comp, char *text, int inplace,
-       int datesw, int delete, int append)
+annosbr(int fd, char *file, char *comp, char *text, int datesw, int delete,
+               int append)
 {
        int mode, tmpfd;
        char *cp, *sp;
-       char buffer[BUFSIZ], tmpfil[BUFSIZ];
+       char tmpfil[BUFSIZ];
        struct stat st;
        FILE *tmp;
        int c;  /* current character */
@@ -297,7 +297,7 @@ annosbr(int fd, char *file, char *comp, char *text, int inplace,
 
                        if (strncasecmp(field, comp, length) == 0 && field[length] == ':') {
                                if (delete == 0) {
-                                       if (text == (char *)0)
+                                       if (text == NULL)
                                                break;
 
                                        for (cp = field + length + 1; *cp == ' ' || *cp == '\t'; cp++)
@@ -308,7 +308,7 @@ annosbr(int fd, char *file, char *comp, char *text, int inplace,
                                                                break;
                                        }
                                        else {
-                                               if ((sp = strrchr(cp, '/')) != (char *)0)
+                                               if ((sp = strrchr(cp, '/')) != NULL)
                                                        cp = sp + 1;
 
                                                if (strcmp(cp, text) == 0)
@@ -406,43 +406,23 @@ annosbr(int fd, char *file, char *comp, char *text, int inplace,
        cpydata(fd, fileno(tmp), file, tmpfil);
        fclose(tmp);
 
-       if (inplace) {
-               if ((tmpfd = open(tmpfil, O_RDONLY)) == NOTOK)
-                       adios(tmpfil, "unable to open for re-reading");
+       if ((tmpfd = open(tmpfil, O_RDONLY)) == NOTOK)
+               adios(tmpfil, "unable to open for re-reading");
 
-               lseek(fd, (off_t) 0, SEEK_SET);
+       lseek(fd, (off_t) 0, SEEK_SET);
 
-               /*
-               **  We're making the file shorter if we're deleting a
-               **  header field so the file has to be truncated or it
-               **  will contain garbage.
-               */
-
-               if (delete >= -1 && ftruncate(fd, 0) == -1)
-                       adios(tmpfil, "unable to truncate.");
+       /*
+       **  We're making the file shorter if we're deleting a
+       **  header field so the file has to be truncated or it
+       **  will contain garbage.
+       */
 
-               cpydata(tmpfd, fd, tmpfil, file);
-               close(tmpfd);
-               unlink(tmpfil);
-       } else {
-               strncpy(buffer, m_backup(file), sizeof(buffer));
-               if (rename(file, buffer) == NOTOK) {
-                       switch (errno) {
-                               case ENOENT:  /* unlinked early - no annotations */
-                                       unlink(tmpfil);
-                                       break;
+       if (delete >= -1 && ftruncate(fd, 0) == -1)
+               adios(tmpfil, "unable to truncate.");
 
-                               default:
-                                       admonish(buffer, "unable to rename %s to", file);
-                                       break;
-                       }
-                       return 1;
-               }
-               if (rename(tmpfil, file) == NOTOK) {
-                       admonish(file, "unable to rename %s to", tmpfil);
-                       return 1;
-               }
-       }
+       cpydata(tmpfd, fd, tmpfil, file);
+       close(tmpfd);
+       unlink(tmpfil);
 
        /*
        ** Close the delete file so that we don't run out of file pointers if