aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-12-28 03:29:33 -0600
committerRob Landley <rob@landley.net>2007-12-28 03:29:33 -0600
commit07c78d338b1adf0c3d32c3670f21e9b066d740da (patch)
treea27378287b8f67d881014d2e6ca8cd92e0130e09 /toys
parent5a0660f513e008192860dc71988e561386c5ecdb (diff)
downloadtoybox-07c78d338b1adf0c3d32c3670f21e9b066d740da.tar.gz
Make touch work reliably when file doesn't exist and clean up headers a bit.
Diffstat (limited to 'toys')
-rw-r--r--toys/touch.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/toys/touch.c b/toys/touch.c
index da93ffc5..e01d157e 100644
--- a/toys/touch.c
+++ b/toys/touch.c
@@ -7,20 +7,14 @@
* See http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html
*/
-#define _XOPEN_SOURCE 600
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <utime.h>
-#include <time.h>
#include "toys.h"
-#define OPT_MTIME 0x01
-#define OPT_NOCREATE 0x02
-#define OPT_ATIME 0x04
-#define OPT_REFERENCE 0x08
-#define OPT_TIME 0x10
-#define OPT_LENGTH 0x20
+#define OPT_MTIME 0x01
+#define OPT_NOCREATE 0x02
+#define OPT_ATIME 0x04
+#define OPT_REFERENCE 0x08
+#define OPT_TIME 0x10
+#define OPT_LENGTH 0x20
void touch_main(void)
{
@@ -65,10 +59,11 @@ void touch_main(void)
buf.modtime = curr_m;
buf.actime = curr_a;
- if (stat(arg, &sb) == -1) {
- if (!(toys.optflags & OPT_NOCREATE) && errno == ENOENT) {
- if (creat(arg, 0644))
- goto error;
+ if (stat(arg, &sb)) {
+ if (!(toys.optflags & OPT_NOCREATE)) {
+ int temp = umask(0);
+ xcreate(arg, O_CREAT, 0644);
+ if (CFG_TOYBOX_FREE) umask(temp);
if (stat(arg, &sb))
goto error;
}