src/lib/osunix.c 1.45
1.45 2010/02/24 00:51:00 angie
Added touchFile (like touch command).
Index: src/lib/osunix.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/lib/osunix.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -b -B -U 4 -r1.44 -r1.45
--- src/lib/osunix.c 22 Nov 2009 00:18:04 -0000 1.44
+++ src/lib/osunix.c 24 Feb 2010 00:51:00 -0000 1.45
@@ -12,8 +12,9 @@
#include "portable.h"
#include "portimpl.h"
#include <sys/wait.h>
#include <regex.h>
+#include <utime.h>
static char const rcsid[] = "$Id$";
@@ -610,4 +611,22 @@
va_start(args, format);
vaDumpStack(format, args);
va_end(args);
}
+
+void touchFile(char *fileName)
+/* If file exists, set its access and mod times to now. If it doesn't exist, create it. */
+{
+if (fileExists(fileName))
+ {
+ struct utimbuf ut;
+ ut.actime = ut.modtime = clock1();
+ int ret = utime(fileName, &ut);
+ if (ret != 0)
+ errnoAbort("utime(%s, clock1()) failed", fileName);
+ }
+else
+ {
+ FILE *f = mustOpen(fileName, "w");
+ carefulClose(&f);
+ }
+}