From: sof Date: Fri, 25 May 2001 01:15:07 +0000 (+0000) Subject: [project @ 2001-05-25 01:15:07 by sof] X-Git-Tag: Approximately_9120_patches~1879 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=c391055fa14cc9901d2ec458c4a2779a84f82b9a;p=ghc-hetmet.git [project @ 2001-05-25 01:15:07 by sof] 'touch' replacement (for use under Win32 in a cygwin-free setup only) --- diff --git a/ghc/utils/touchy/Makefile b/ghc/utils/touchy/Makefile new file mode 100644 index 0000000..ea018b4 --- /dev/null +++ b/ghc/utils/touchy/Makefile @@ -0,0 +1,19 @@ +# +# Substitute for 'touch' on win32 platforms (without an Unix toolset installed). +# +TOP=../.. +include $(TOP)/mk/boilerplate.mk + +C_SRCS=touchy.c +C_PROG=touchy +SRC_CC_OPTS += -O + +# Get it over with! +boot :: all + +# +# Install touchy in lib/.* +# +INSTALL_LIBEXECS += $(C_PROG) + +include $(TOP)/mk/target.mk diff --git a/ghc/utils/touchy/touchy.c b/ghc/utils/touchy/touchy.c new file mode 100644 index 0000000..71a58ba --- /dev/null +++ b/ghc/utils/touchy/touchy.c @@ -0,0 +1,63 @@ +/* + * Simple _utime() wrapper for setting the mod. time on files + * to the current system time. + * + */ +#if !defined(_MSC_VER) && !defined(__MINGW__) && !defined(_WIN32) +#error "Win32-only, the platform you're using is supposed to have 'touch' already." +#else +#include +#include +#include +#include +#include + +int +main(int argc, char** argv) +{ + int rc; + int i=0; + int fd; + int wBitSet = 0; + struct _stat sb; + + if (argc == 1) { + fprintf(stderr, "Usage: %s \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; + } + if ( (rc = _utime(argv[i],NULL)) < 0) { + fprintf(stderr, "Unable to change mod. time for %s (%d)\n", argv[i], errno); + } + if (wBitSet) { + /* Turn the file back into a read-only file */ + _chmod(argv[i], (sb.st_mode & _S_IREAD)); + wBitSet = 0; + } + } + + return 0; +} +#endif