Repository : ssh://darcs.haskell.org//srv/darcs/ghc On branch : master
http://hackage.haskell.org/trac/ghc/changeset/8d226e286252928452c2572d5a92ba31e0d0af2a >--------------------------------------------------------------- commit 8d226e286252928452c2572d5a92ba31e0d0af2a Author: Ian Lynagh <ig...@earth.li> Date: Wed Oct 31 01:08:45 2012 +0100 Improve touchy It's now simpler, and it fails if something fails rather than just printing an error message and continuing. >--------------------------------------------------------------- utils/touchy/touchy.c | 81 ++++++++++++++++-------------------------------- 1 files changed, 27 insertions(+), 54 deletions(-) diff --git a/utils/touchy/touchy.c b/utils/touchy/touchy.c index 93e960d..7252012 100644 --- a/utils/touchy/touchy.c +++ b/utils/touchy/touchy.c @@ -83,63 +83,36 @@ so now we use the Win32 functions GetSystemTimeAsFileTime and SetFileTime. int main(int argc, char** argv) { - int i=0; - int fd; - int wBitSet = 0; - struct _stat sb; - FILETIME ft; - BOOL b; - HANDLE hFile; + int i; + FILETIME ft; + BOOL b; + HANDLE hFile; - if (argc == 1) { - fprintf(stderr, "Usage: %s <files>\n", argv[0]); - return 1; - } - - - while (i++ < (argc-1)) { - if ( (_access(argv[i], 00) < 0) && (errno == ENOENT || errno == EACCES) ) { - /* File doesn't exist, try creating it. */ - if ( (fd = _open(argv[i], _O_CREAT | _O_EXCL | _O_TRUNC, _S_IREAD | _S_IWRITE)) < 0 ) { - fprintf(stderr, "Unable to create %s, skipping.\n", argv[i]); - } else { - _close(fd); - } - } - if ( (_access(argv[i], 02)) < 0 ) { - /* No write permission, try setting it first. */ - if (_stat(argv[i], &sb) < 0) { - fprintf(stderr, "Unable to change mod. time for %s (%d)\n", argv[i], errno); - continue; - } - if (_chmod(argv[i], (sb.st_mode & _S_IREAD) | _S_IWRITE) < 0) { - fprintf(stderr, "Unable to change mod. time for %s (%d)\n", argv[i], errno); - continue; - } - wBitSet = 1; - } - hFile = CreateFile(argv[i], GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, - FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) { - fprintf(stderr, "Unable to open %s\n", argv[i]); - continue; + if (argc == 1) { + fprintf(stderr, "Usage: %s <files>\n", argv[0]); + return 1; } - GetSystemTimeAsFileTime(&ft); - b = SetFileTime(hFile, (LPFILETIME) NULL, (LPFILETIME) NULL, &ft); - if (b == 0) { - fprintf(stderr, "Unable to change mod. time for %s\n", argv[i]); - } - b = CloseHandle(hFile); - if (b == 0) { - fprintf(stderr, "Closing failed for %s\n", argv[i]); - } - if (wBitSet) { - /* Turn the file back into a read-only file */ - _chmod(argv[i], (sb.st_mode & _S_IREAD)); - wBitSet = 0; + + for (i = 1; i < argc; i++) { + hFile = CreateFile(argv[i], GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) { + fprintf(stderr, "Unable to open %s\n", argv[i]); + exit(1); + } + GetSystemTimeAsFileTime(&ft); + b = SetFileTime(hFile, (LPFILETIME) NULL, (LPFILETIME) NULL, &ft); + if (b == 0) { + fprintf(stderr, "Unable to change mod. time for %s\n", argv[i]); + exit(1); + } + b = CloseHandle(hFile); + if (b == 0) { + fprintf(stderr, "Closing failed for %s\n", argv[i]); + exit(1); + } } - } - return 0; + return 0; } #endif _______________________________________________ Cvs-ghc mailing list Cvs-ghc@haskell.org http://www.haskell.org/mailman/listinfo/cvs-ghc