/******************************************************************************* * * timestamp++.c * * AUTHOR: * Dan Harkless * * COPYRIGHT: * This file is Copyright (C) 2002 by Dan Harkless, and is released under the * GNU General Public License . * * USAGE: * % timestamp++ [...] * * DESCRIPTION: * Increments the modification time on one or more files by 1 second. The * access time of the file(s) will be preserved. If one of the specified files * doesn't exist or has a permissions problem, an error will be issued and the * program will ultimately exit with nonzero status, but the remaining files * will still be processed in the meantime. * * DATE MODIFICATION * ========== ================================================================== * 2002-03-16 Upgraded to work with more than one file. * 1999-04-09 Failing to open a file doesn't necessarily mean it doesn't exist. * 1998-02-24 Original. * *******************************************************************************/ #include /* supposed to precede and */ #include /* for errno */ #include /* for fprintf(), etc. */ #include /* for EXIT_FAILURE and EXIT_SUCCESS */ #include /* for strerror() and strrchr() */ #include /* for stat() and struct stat */ #include /* for struct utimbuf and utime() */ int main(int argc, char** argv) { char* last_slash = strrchr(argv[0], '/'); char* our_program_name; int exit_status = EXIT_SUCCESS, i; if (last_slash == NULL) our_program_name = argv[0]; else our_program_name = last_slash + 1; if (argc < 2) { fprintf(stderr, "Usage: %s [...]\n", our_program_name); return EXIT_FAILURE; } for (i = 1; i < argc; i++) { struct stat file_stat; if (stat(argv[i], &file_stat) < 0) { fprintf(stderr, "%s: \"%s\": %s.\n", our_program_name, argv[i], strerror(errno)); exit_status = EXIT_FAILURE; } else { struct utimbuf timestamp_struct; timestamp_struct.actime = file_stat.st_atime; timestamp_struct.modtime = file_stat.st_mtime + 1; if (utime(argv[i], ×tamp_struct) < 0) { fprintf(stderr, "%s: \"%s\": %s.\n", our_program_name, argv[i], strerror(errno)); exit_status = EXIT_FAILURE; } } } return exit_status; }