2 * Simple _utime() wrapper for setting the mod. time on files
3 * to the current system time.
6 #if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_WIN32)
7 #error "Win32-only, the platform you're using is supposed to have 'touch' already."
11 #include <sys/types.h>
16 main(int argc, char** argv)
25 fprintf(stderr, "Usage: %s <files>\n", argv[0]);
30 while (i++ < (argc-1)) {
31 if ( (_access(argv[i], 00) < 0) && (errno == ENOENT || errno == EACCES) ) {
32 /* File doesn't exist, try creating it. */
33 if ( (fd = _open(argv[i], _O_CREAT | _O_EXCL | _O_TRUNC, _S_IREAD | _S_IWRITE)) < 0 ) {
34 fprintf(stderr, "Unable to create %s, skipping.\n", argv[i]);
39 if ( (_access(argv[i], 02)) < 0 ) {
40 /* No write permission, try setting it first. */
41 if (_stat(argv[i], &sb) < 0) {
42 fprintf(stderr, "Unable to change mod. time for %s (%d)\n", argv[i], errno);
45 if (_chmod(argv[i], (sb.st_mode & _S_IREAD) | _S_IWRITE) < 0) {
46 fprintf(stderr, "Unable to change mod. time for %s (%d)\n", argv[i], errno);
51 if ( (rc = _utime(argv[i],NULL)) < 0) {
52 fprintf(stderr, "Unable to change mod. time for %s (%d)\n", argv[i], errno);
55 /* Turn the file back into a read-only file */
56 _chmod(argv[i], (sb.st_mode & _S_IREAD));