X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fannosbr.c;h=d1e39b055729a2a86692b70f6f066051c7ceb57a;hp=e8c03e172c208b608736b0d36cdf78128aa2cce5;hb=88a0787554de9c618e657c31940e734178a25730;hpb=5b792c4424571f05bc2008e3109797d18d7d00d1 diff --git a/uip/annosbr.c b/uip/annosbr.c index e8c03e1..d1e39b0 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -17,20 +17,12 @@ /* ** 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 -** allows additional functionality to be added to anno without piling -** on yet another annotate() argument. -*/ - -/* set to preserve access and modification times on annotated message */ -static int preserve_actime_and_modtime = 0; int -annotate(char *file, char *comp, char *text, int inplace, int datesw, - int delete, int append) +annotate(char *file, char *comp, char *text, int datesw, + int delete, int append, int preserve) { int i, fd; struct utimbuf b; @@ -51,15 +43,15 @@ annotate(char *file, char *comp, char *text, int inplace, int datesw, if (stat(file, &s) == -1) { advise("can't get access and modification times for %s", file); - preserve_actime_and_modtime = 0; + preserve = 0; } 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) + if (preserve && utime(file, &b) == -1) advise("can't set access and modification times for %s", file); lkclose(fd, file); @@ -150,24 +142,13 @@ annolist(char *file, char *comp, char *text, int number) return; } -/* -** Set the preserve-times flag. This hack eliminates the need for an -** additional argument to annotate(). -*/ -void -annopreserve(int preserve) -{ - preserve_actime_and_modtime = preserve; - return; -} - 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 */ @@ -406,44 +387,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"); - - lseek(fd, (off_t) 0, SEEK_SET); + if ((tmpfd = open(tmpfil, O_RDONLY)) == NOTOK) + adios(tmpfil, "unable to open for re-reading"); - /* - ** 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. - */ + lseek(fd, (off_t) 0, SEEK_SET); - 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