diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-28 01:18:09 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-28 01:18:09 +0000 |
| commit | ed90bdabb4a1f9fc672d58ad4cce8b56060f6e12 (patch) | |
| tree | 7546bafa7f26baed492505da8df0ca907afbd539 /coreutils | |
| parent | b75fe798bb26fbf16a3251decd72bc20b44a00c5 (diff) | |
| download | busybox-w32-ed90bdabb4a1f9fc672d58ad4cce8b56060f6e12.tar.gz busybox-w32-ed90bdabb4a1f9fc672d58ad4cce8b56060f6e12.tar.bz2 busybox-w32-ed90bdabb4a1f9fc672d58ad4cce8b56060f6e12.zip | |
touch: support -r REF_FILE if ENABLE_DESKTOP (needed for blackfin compile)
function old new delta
touch_main 136 221 +85
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/touch.c | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/coreutils/touch.c b/coreutils/touch.c index 0b58179e7..78ae4a5c3 100644 --- a/coreutils/touch.c +++ b/coreutils/touch.c | |||
| @@ -21,24 +21,55 @@ | |||
| 21 | 21 | ||
| 22 | /* This is a NOFORK applet. Be very careful! */ | 22 | /* This is a NOFORK applet. Be very careful! */ |
| 23 | 23 | ||
| 24 | /* coreutils implements: | ||
| 25 | * -a change only the access time | ||
| 26 | * -c, --no-create | ||
| 27 | * do not create any files | ||
| 28 | * -d, --date=STRING | ||
| 29 | * parse STRING and use it instead of current time | ||
| 30 | * -f (ignored, BSD compat) | ||
| 31 | * -m change only the modification time | ||
| 32 | * -r, --reference=FILE | ||
| 33 | * use this file's times instead of current time | ||
| 34 | * -t STAMP | ||
| 35 | * use [[CC]YY]MMDDhhmm[.ss] instead of current time | ||
| 36 | * --time=WORD | ||
| 37 | * change the specified time: WORD is access, atime, or use | ||
| 38 | */ | ||
| 39 | |||
| 24 | int touch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 40 | int touch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 25 | int touch_main(int argc ATTRIBUTE_UNUSED, char **argv) | 41 | int touch_main(int argc ATTRIBUTE_UNUSED, char **argv) |
| 26 | { | 42 | { |
| 43 | #if ENABLE_DESKTOP | ||
| 44 | struct utimbuf timebuf; | ||
| 45 | char *reference_file = NULL; | ||
| 46 | #else | ||
| 47 | #define reference_file NULL | ||
| 48 | #define timebuf (*(struct utimbuf*)NULL) | ||
| 49 | #endif | ||
| 27 | int fd; | 50 | int fd; |
| 28 | int status = EXIT_SUCCESS; | 51 | int status = EXIT_SUCCESS; |
| 29 | int flags = getopt32(argv, "cf"); | 52 | int flags = getopt32(argv, "c" USE_DESKTOP("r:") |
| 53 | /*ignored:*/ "fma" | ||
| 54 | USE_DESKTOP(, &reference_file)); | ||
| 30 | 55 | ||
| 31 | flags &= 1; /* ignoring -f (BSD compat thingy) */ | 56 | flags &= 1; /* only -c bit is left */ |
| 32 | argv += optind; | 57 | argv += optind; |
| 33 | |||
| 34 | if (!*argv) { | 58 | if (!*argv) { |
| 35 | bb_show_usage(); | 59 | bb_show_usage(); |
| 36 | } | 60 | } |
| 37 | 61 | ||
| 62 | if (reference_file) { | ||
| 63 | struct stat stbuf; | ||
| 64 | xstat(reference_file, &stbuf); | ||
| 65 | timebuf.actime = stbuf.st_atime; | ||
| 66 | timebuf.modtime = stbuf.st_mtime; | ||
| 67 | } | ||
| 68 | |||
| 38 | do { | 69 | do { |
| 39 | if (utime(*argv, NULL)) { | 70 | if (utime(*argv, reference_file ? &timebuf : NULL)) { |
| 40 | if (errno == ENOENT) { /* no such file */ | 71 | if (errno == ENOENT) { /* no such file */ |
| 41 | if (flags) { /* Creation is disabled, so ignore. */ | 72 | if (flags) { /* creation is disabled, so ignore */ |
| 42 | continue; | 73 | continue; |
| 43 | } | 74 | } |
| 44 | /* Try to create the file. */ | 75 | /* Try to create the file. */ |
| @@ -46,6 +77,8 @@ int touch_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 46 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | 77 | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH |
| 47 | ); | 78 | ); |
| 48 | if ((fd >= 0) && !close(fd)) { | 79 | if ((fd >= 0) && !close(fd)) { |
| 80 | if (reference_file) | ||
| 81 | utime(*argv, &timebuf); | ||
| 49 | continue; | 82 | continue; |
| 50 | } | 83 | } |
| 51 | } | 84 | } |
