/******************************************************************************* * * timecopy.c * * AUTHOR: * Dan Harkless * * COPYRIGHT: * This file is Copyright (C) 2002 by Dan Harkless, and is released under the * GNU General Public License . * * USAGE: * % timecopy [...] * * DESCRIPTION: * Copies the access and modification timestamps from a source file to one or * more destination files. If one of the specified destination 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 destination * files will still be processed in the meantime. * * DATE MODIFICATION * ========== ================================================================== * 2002-03-16 Upgraded to work with more than one destination file. * 1999-04-09 Failing to open a file doesn't necessarily mean it doesn't exist. * 1995-08-29 Original. * *******************************************************************************/ #include /* supposed to precede and */ #include /* for errno */ #include /* for EXIT_FAILURE and EXIT_SUCCESS */ #include /* for fprintf(), etc. */ #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; struct stat src_stat; struct utimbuf timestamp_struct; if (last_slash == NULL) our_program_name = argv[0]; else our_program_name = last_slash + 1; if (argc < 3) { fprintf(stderr, "Usage: %s [...]\n", our_program_name); return EXIT_FAILURE; } if (stat(argv[1], &src_stat) < 0) { fprintf(stderr, "%s: \"%s\": %s.\n", our_program_name, argv[1], strerror(errno)); return EXIT_FAILURE; } timestamp_struct.actime = src_stat.st_atime; timestamp_struct.modtime = src_stat.st_mtime; for (i = 2; i < argc; i++) 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; }