aboutsummaryrefslogtreecommitdiff
path: root/coreutils/touch.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-06-02 23:26:44 +0000
committerEric Andersen <andersen@codepoet.org>2000-06-02 23:26:44 +0000
commit5a0a2aa00be4a19dd52b65b70c7cc6d944a5aef6 (patch)
treec2256921b9067191a1a556d1e3244b4105fb9e27 /coreutils/touch.c
parent808d03ec19e0c8f0c06d9a9defb85fc9a1100441 (diff)
downloadbusybox-w32-5a0a2aa00be4a19dd52b65b70c7cc6d944a5aef6.tar.gz
busybox-w32-5a0a2aa00be4a19dd52b65b70c7cc6d944a5aef6.tar.bz2
busybox-w32-5a0a2aa00be4a19dd52b65b70c7cc6d944a5aef6.zip
Fix touch so it behaves itself (it could segfault in some cases).
Fix uname help info formatting. -Erik
Diffstat (limited to 'coreutils/touch.c')
-rw-r--r--coreutils/touch.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/coreutils/touch.c b/coreutils/touch.c
index 207692826..1364bb7d5 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -33,26 +33,21 @@
33 33
34static const char touch_usage[] = "touch [-c] file [file ...]\n" 34static const char touch_usage[] = "touch [-c] file [file ...]\n"
35#ifndef BB_FEATURE_TRIVIAL_HELP 35#ifndef BB_FEATURE_TRIVIAL_HELP
36 "\nUpdate the last-modified date on the given file[s].\n" 36 "\nUpdate the last-modified date on the given file[s].\n\n"
37 "Options:\n"
38 "\t-c\tDo not create any files\n"
37#endif 39#endif
38 ; 40 ;
39 41
40 42
41
42extern int touch_main(int argc, char **argv) 43extern int touch_main(int argc, char **argv)
43{ 44{
44 int fd; 45 int fd;
45 int create = TRUE; 46 int create = TRUE;
46 47
47 if (argc < 2) {
48 usage(touch_usage);
49 }
50 argc--;
51 argv++;
52
53 /* Parse options */ 48 /* Parse options */
54 while (**argv == '-') { 49 while (--argc > 0 && **(++argv) == '-') {
55 while (*++(*argv)) 50 while (*(++(*argv))) {
56 switch (**argv) { 51 switch (**argv) {
57 case 'c': 52 case 'c':
58 create = FALSE; 53 create = FALSE;
@@ -61,23 +56,30 @@ extern int touch_main(int argc, char **argv)
61 usage(touch_usage); 56 usage(touch_usage);
62 exit(FALSE); 57 exit(FALSE);
63 } 58 }
64 argc--; 59 }
65 argv++;
66 } 60 }
67 61
68 fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT, 0644); 62 if (argc < 1) {
69 if (fd < 0) { 63 usage(touch_usage);
70 if (create == FALSE && errno == ENOENT) 64 }
71 exit(TRUE); 65
72 else { 66 while (argc > 0) {
73 perror("touch"); 67 fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT,
74 exit(FALSE); 68 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
69 if (fd < 0) {
70 if (create == FALSE && errno == ENOENT)
71 exit(TRUE);
72 else {
73 fatalError("touch: %s", strerror(errno));
74 }
75 }
76 close(fd);
77 if (utime(*argv, NULL)) {
78 fatalError("touch: %s", strerror(errno));
75 } 79 }
80 argc--;
81 argv++;
76 } 82 }
77 close(fd); 83
78 if (utime(*argv, NULL)) { 84 exit(TRUE);
79 perror("touch");
80 exit(FALSE);
81 } else
82 exit(TRUE);
83} 85}