Just Minor change before code release to next version <img goomoji="347" style="margin: 0px 0.2ex; vertical-align: middle;" src="cid:347@goomoji.gmail"><br>(Please find my change in USE_xx part)<br><br>//Gaurang Shastri<br>
<br><div class="gmail_quote">On Thu, Aug 16, 2012 at 9:26 AM, Avery Pennarun <span dir="ltr"><<a href="mailto:apenwarr@gmail.com" target="_blank">apenwarr@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Doesn't implement optional manual setting of timestamp; just uses the<br>
current time, which is the most common use case.<br>
---<br>
toys.h | 1 +<br>
toys/touch.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++<br>
2 files changed, 58 insertions(+), 0 deletions(-)<br>
create mode 100644 toys/touch.c<br>
<br>
diff --git a/toys.h b/toys.h<br>
index 4a84bf4..2cc58af 100644<br>
--- a/toys.h<br>
+++ b/toys.h<br>
@@ -37,6 +37,7 @@<br>
#include <sys/statvfs.h><br>
#include <sys/sysinfo.h><br>
#include <sys/swap.h><br>
+#include <sys/time.h><br>
#include <sys/times.h><br>
#include <sys/types.h><br>
#include <sys/utsname.h><br>
diff --git a/toys/touch.c b/toys/touch.c<br>
new file mode 100644<br>
index 0000000..4bbfacd<br>
--- /dev/null<br>
+++ b/toys/touch.c<br>
@@ -0,0 +1,57 @@<br>
+/* vi: set sw=4 ts=4:<br>
+ *<br>
+ * touch.c - Create files and update their atime/mtime.<br>
+ *<br>
+ * Copyright 2012 Avery Pennarun <<a href="mailto:apenwarr@gmail.com">apenwarr@gmail.com</a>><br>
+ *<br>
+ * See <a href="http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html" target="_blank">http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html</a><br>
+ *<br><b style="color:rgb(51,102,255)">- USE_CP(NEWTOY(touch, "<1", TOYFLAG_BIN))<br></b></blockquote><div style="color:rgb(51,102,255)"><b> + USE_TOUCH(NEWTOY(touch, "<1", TOYFLAG_BIN))</b> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><b>
</b>+<br>
+config TOUCH<br>
+ bool "touch"<br>
+ default n<br>
+ help<br>
+ usage: touch <filenames...><br>
+<br>
+ Updates the timestamps on the given files, and creates them if<br>
+ they do not exist.<br>
+*/<br>
+<br>
+#include "toys.h"<br>
+<br>
+#define TT this.touch<br>
+<br>
+<br>
+void touch_file(char *filename, struct timeval *times)<br>
+{<br>
+ int fd = -1;<br>
+<br>
+ if (utimes(filename, times) < 0) {<br>
+ if (errno != ENOENT) {<br>
+ perror_exit("utimes(%s)", filename);<br>
+ } else {<br>
+ fd = open(filename, O_WRONLY|O_CREAT, 0666);<br>
+ if (fd < 0) {<br>
+ perror_exit("open '%s'", filename);<br>
+ }<br>
+ xclose(fd);<br>
+ }<br>
+ }<br>
+}<br>
+<br>
+<br>
+void touch_main(void)<br>
+{<br>
+ struct timeval times[2];<br>
+ struct timezone tz;<br>
+ int i;<br>
+<br>
+ gettimeofday(×[0], &tz);<br>
+ times[1] = times[0];<br>
+<br>
+ for (i=0; i<toys.optc; i++) {<br>
+ char *filename = toys.optargs[i];<br>
+ touch_file(filename, times);<br>
+ }<br>
+}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.9.dirty<br>
<br>
_______________________________________________<br>
Toybox mailing list<br>
<a href="mailto:Toybox@lists.landley.net">Toybox@lists.landley.net</a><br>
<a href="http://lists.landley.net/listinfo.cgi/toybox-landley.net" target="_blank">http://lists.landley.net/listinfo.cgi/toybox-landley.net</a><br>
</font></span></blockquote></div><br>