summaryrefslogtreecommitdiff
path: root/utils/touchy
diff options
context:
space:
mode:
authorSimon Marlow <simonmar@microsoft.com>2006-04-07 02:05:11 +0000
committerSimon Marlow <simonmar@microsoft.com>2006-04-07 02:05:11 +0000
commit0065d5ab628975892cea1ec7303f968c3338cbe1 (patch)
tree8e2afe0ab48ee33cf95009809d67c9649573ef92 /utils/touchy
parent28a464a75e14cece5db40f2765a29348273ff2d2 (diff)
downloadhaskell-0065d5ab628975892cea1ec7303f968c3338cbe1.tar.gz
Reorganisation of the source tree
Most of the other users of the fptools build system have migrated to Cabal, and with the move to darcs we can now flatten the source tree without losing history, so here goes. The main change is that the ghc/ subdir is gone, and most of what it contained is now at the top level. The build system now makes no pretense at being multi-project, it is just the GHC build system. No doubt this will break many things, and there will be a period of instability while we fix the dependencies. A straightforward build should work, but I haven't yet fixed binary/source distributions. Changes to the Building Guide will follow, too.
Diffstat (limited to 'utils/touchy')
-rw-r--r--utils/touchy/Makefile20
-rw-r--r--utils/touchy/touchy.c63
2 files changed, 83 insertions, 0 deletions
diff --git a/utils/touchy/Makefile b/utils/touchy/Makefile
new file mode 100644
index 0000000000..d2430df162
--- /dev/null
+++ b/utils/touchy/Makefile
@@ -0,0 +1,20 @@
+#
+# 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
+
+#
+# Install touchy in lib/.*
+#
+INSTALL_LIBEXECS += $(C_PROG)
+
+include $(TOP)/mk/target.mk
+
+# Get it over with!
+boot :: all
+
diff --git a/utils/touchy/touchy.c b/utils/touchy/touchy.c
new file mode 100644
index 0000000000..90fb31e93e
--- /dev/null
+++ b/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(__MINGW32__) && !defined(_WIN32)
+#error "Win32-only, the platform you're using is supposed to have 'touch' already."
+#else
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+
+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 <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;
+ }
+ 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