aboutsummaryrefslogtreecommitdiff
path: root/util/subst.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/subst.c')
-rw-r--r--util/subst.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/util/subst.c b/util/subst.c
index dff1848b..0c618a86 100644
--- a/util/subst.c
+++ b/util/subst.c
@@ -11,6 +11,9 @@
#include <unistd.h>
#include <string.h>
#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <utime.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
@@ -289,7 +292,6 @@ static int compare_file(const char *outfn, const char *newfn)
return retval;
}
-
int main(int argc, char **argv)
@@ -299,8 +301,11 @@ int main(int argc, char **argv)
FILE *in, *out;
char *outfn = NULL, *newfn = NULL;
int verbose = 0;
+ int adjust_timestamp = 0;
+ struct stat stbuf;
+ struct utimbuf ut;
- while ((c = getopt (argc, argv, "f:v")) != EOF) {
+ while ((c = getopt (argc, argv, "f:tv")) != EOF) {
switch (c) {
case 'f':
in = fopen(optarg, "r");
@@ -311,6 +316,9 @@ int main(int argc, char **argv)
parse_config_file(in);
fclose(in);
break;
+ case 't':
+ adjust_timestamp++;
+ break;
case 'v':
verbose++;
break;
@@ -361,6 +369,16 @@ int main(int argc, char **argv)
if (compare_file(outfn, newfn)) {
if (verbose)
printf("No change, keeping %s.\n", outfn);
+ if (adjust_timestamp) {
+ if (stat(outfn, &stbuf) == 0) {
+ if (verbose)
+ printf("Updating modtime for %s\n", outfn);
+ ut.actime = stbuf.st_atime;
+ ut.modtime = time(0);
+ if (utime(outfn, &ut) < 0)
+ perror("utime");
+ }
+ }
unlink(newfn);
} else {
if (verbose)