aboutsummaryrefslogtreecommitdiff
path: root/coreutils/touch.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
commite49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /coreutils/touch.c
parentc0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff)
downloadbusybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'coreutils/touch.c')
-rw-r--r--coreutils/touch.c79
1 files changed, 37 insertions, 42 deletions
diff --git a/coreutils/touch.c b/coreutils/touch.c
index d2d3e9484..a0f21acdd 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini touch implementation for busybox 3 * Mini touch implementation for busybox
3 * 4 *
@@ -31,56 +32,50 @@
31 32
32 33
33static const char touch_usage[] = "touch [-c] file [file ...]\n\n" 34static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
34"Update the last-modified date on the given file[s].\n";
35 35
36 "Update the last-modified date on the given file[s].\n";
36 37
37 38
38extern int
39touch_main(int argc, char **argv)
40{
41 int fd;
42 int create=TRUE;
43 39
44 if (argc < 2) { 40extern int touch_main(int argc, char **argv)
45 usage( touch_usage); 41{
46 } 42 int fd;
47 argc--; 43 int create = TRUE;
48 argv++;
49 44
50 /* Parse options */ 45 if (argc < 2) {
51 while (**argv == '-') { 46 usage(touch_usage);
52 while (*++(*argv)) switch (**argv) {
53 case 'c':
54 create = FALSE;
55 break;
56 default:
57 usage( touch_usage);
58 exit( FALSE);
59 } 47 }
60 argc--; 48 argc--;
61 argv++; 49 argv++;
62 }
63 50
64 fd = open (*argv, (create==FALSE)? O_RDWR : O_RDWR | O_CREAT, 0644); 51 /* Parse options */
65 if (fd < 0 ) { 52 while (**argv == '-') {
66 if (create==FALSE && errno == ENOENT) 53 while (*++(*argv))
67 exit( TRUE); 54 switch (**argv) {
68 else { 55 case 'c':
69 perror("touch"); 56 create = FALSE;
70 exit( FALSE); 57 break;
58 default:
59 usage(touch_usage);
60 exit(FALSE);
61 }
62 argc--;
63 argv++;
71 } 64 }
72 }
73 close( fd);
74 if (utime (*argv, NULL)) {
75 perror("touch");
76 exit( FALSE);
77 }
78 else
79 exit( TRUE);
80}
81
82
83
84
85
86 65
66 fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT, 0644);
67 if (fd < 0) {
68 if (create == FALSE && errno == ENOENT)
69 exit(TRUE);
70 else {
71 perror("touch");
72 exit(FALSE);
73 }
74 }
75 close(fd);
76 if (utime(*argv, NULL)) {
77 perror("touch");
78 exit(FALSE);
79 } else
80 exit(TRUE);
81}