diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-10-07 08:30:23 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-10-07 08:30:23 +0000 |
commit | 596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe (patch) | |
tree | 4d48d109e66c5197bb27c8215062aab28d385509 /coreutils/touch.c | |
parent | 5c3199e0a519695c367b773e179b5458670f452b (diff) | |
download | busybox-w32-596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe.tar.gz busybox-w32-596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe.tar.bz2 busybox-w32-596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe.zip |
more stuff
Diffstat (limited to 'coreutils/touch.c')
-rw-r--r-- | coreutils/touch.c | 87 |
1 files changed, 76 insertions, 11 deletions
diff --git a/coreutils/touch.c b/coreutils/touch.c index ca4b98108..8dac10294 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c | |||
@@ -1,20 +1,85 @@ | |||
1 | /* | ||
2 | * Mini touch implementation for busybox | ||
3 | * | ||
4 | * Copyright (C) 1998 by Erik Andersen <andersee@debian.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | * | ||
20 | */ | ||
21 | |||
1 | #include "internal.h" | 22 | #include "internal.h" |
2 | #include <sys/types.h> | ||
3 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <fcntl.h> | ||
4 | #include <utime.h> | 27 | #include <utime.h> |
28 | #include <errno.h> | ||
29 | |||
5 | 30 | ||
6 | const char touch_usage[] = "touch [-c] file [file ...]\n" | 31 | const char touch_usage[] = "touch [-c] file [file ...]\n\n" |
7 | "\n" | ||
8 | "\tUpdate the last-modified date on the given file[s].\n"; | 32 | "\tUpdate the last-modified date on the given file[s].\n"; |
9 | 33 | ||
10 | extern int | 34 | |
11 | touch_fn(const struct FileInfo * i) | 35 | |
36 | extern int | ||
37 | touch_main(int argc, char **argv) | ||
12 | { | 38 | { |
13 | if ( (utime(i->source, 0) != 0) && (i->create != 1) ) { | 39 | int fd; |
14 | if ( fopen(i->source, "w") == NULL ) { | 40 | int create=TRUE; |
15 | name_and_error(i->source); | 41 | |
16 | return 1; | 42 | if (argc < 2) { |
17 | } | 43 | fprintf(stderr, "Usage: %s %s", *argv, touch_usage); |
44 | exit( FALSE); | ||
45 | } | ||
46 | argc--; | ||
47 | argv++; | ||
48 | |||
49 | /* Parse options */ | ||
50 | while (**argv == '-') { | ||
51 | while (*++(*argv)) switch (**argv) { | ||
52 | case 'c': | ||
53 | create = FALSE; | ||
54 | break; | ||
55 | default: | ||
56 | fprintf(stderr, "Unknown option: %c\n", **argv); | ||
57 | exit( FALSE); | ||
18 | } | 58 | } |
19 | return 0; | 59 | argc--; |
60 | argv++; | ||
61 | } | ||
62 | |||
63 | fd = open (*argv, (create==FALSE)? O_RDWR : O_RDWR | O_CREAT, 0644); | ||
64 | if (fd < 0 ) { | ||
65 | if (create==FALSE && errno == ENOENT) | ||
66 | exit( TRUE); | ||
67 | else { | ||
68 | perror("touch"); | ||
69 | exit( FALSE); | ||
70 | } | ||
71 | } | ||
72 | close( fd); | ||
73 | if (utime (*argv, NULL)) { | ||
74 | perror("touch"); | ||
75 | exit( FALSE); | ||
76 | } | ||
77 | else | ||
78 | exit( TRUE); | ||
20 | } | 79 | } |
80 | |||
81 | |||
82 | |||
83 | |||
84 | |||
85 | |||