diff options
| author | Alistair Francis <alistair.francis@wdc.com> | 2019-11-19 13:06:40 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-11-19 13:08:25 +0100 |
| commit | d3539be8f27b8cbfdfee460fe08299158f08bcd9 (patch) | |
| tree | d272de7f4ac324045806ed856e9200e3907982db | |
| parent | 419d0294e9e9c272c0d740e4951dd083d19d479f (diff) | |
| download | busybox-w32-d3539be8f27b8cbfdfee460fe08299158f08bcd9.tar.gz busybox-w32-d3539be8f27b8cbfdfee460fe08299158f08bcd9.tar.bz2 busybox-w32-d3539be8f27b8cbfdfee460fe08299158f08bcd9.zip | |
Remove stime() function calls
stime() has been deprecated in glibc 2.31 and replaced with
clock_settime(). Let's replace the stime() function calls with
clock_settime() in preperation.
function old new delta
rdate_main 197 224 +27
clock_settime - 27 +27
date_main 926 941 +15
stime 37 - -37
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 2/0 up/down: 69/-37) Total: 32 bytes
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | coreutils/date.c | 6 | ||||
| -rw-r--r-- | libbb/missing_syscalls.c | 8 | ||||
| -rw-r--r-- | util-linux/rdate.c | 8 |
3 files changed, 11 insertions, 11 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index f7e9a8d0e..b9b7fd2cb 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
| @@ -276,6 +276,9 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
| 276 | time(&ts.tv_sec); | 276 | time(&ts.tv_sec); |
| 277 | #endif | 277 | #endif |
| 278 | } | 278 | } |
| 279 | #if !ENABLE_FEATURE_DATE_NANO | ||
| 280 | ts.tv_nsec = 0; | ||
| 281 | #endif | ||
| 279 | localtime_r(&ts.tv_sec, &tm_time); | 282 | localtime_r(&ts.tv_sec, &tm_time); |
| 280 | 283 | ||
| 281 | /* If date string is given, update tm_time, and maybe set date */ | 284 | /* If date string is given, update tm_time, and maybe set date */ |
| @@ -298,9 +301,10 @@ int date_main(int argc UNUSED_PARAM, char **argv) | |||
| 298 | if (date_str[0] != '@') | 301 | if (date_str[0] != '@') |
| 299 | tm_time.tm_isdst = -1; | 302 | tm_time.tm_isdst = -1; |
| 300 | ts.tv_sec = validate_tm_time(date_str, &tm_time); | 303 | ts.tv_sec = validate_tm_time(date_str, &tm_time); |
| 304 | ts.tv_nsec = 0; | ||
| 301 | 305 | ||
| 302 | /* if setting time, set it */ | 306 | /* if setting time, set it */ |
| 303 | if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) { | 307 | if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) { |
| 304 | bb_simple_perror_msg("can't set date"); | 308 | bb_simple_perror_msg("can't set date"); |
| 305 | } | 309 | } |
| 306 | } | 310 | } |
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c index 87cf59b3d..dc40d9155 100644 --- a/libbb/missing_syscalls.c +++ b/libbb/missing_syscalls.c | |||
| @@ -15,14 +15,6 @@ pid_t getsid(pid_t pid) | |||
| 15 | return syscall(__NR_getsid, pid); | 15 | return syscall(__NR_getsid, pid); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | int stime(const time_t *t) | ||
| 19 | { | ||
| 20 | struct timeval tv; | ||
| 21 | tv.tv_sec = *t; | ||
| 22 | tv.tv_usec = 0; | ||
| 23 | return settimeofday(&tv, NULL); | ||
| 24 | } | ||
| 25 | |||
| 26 | int sethostname(const char *name, size_t len) | 18 | int sethostname(const char *name, size_t len) |
| 27 | { | 19 | { |
| 28 | return syscall(__NR_sethostname, name, len); | 20 | return syscall(__NR_sethostname, name, len); |
diff --git a/util-linux/rdate.c b/util-linux/rdate.c index 41aade5ea..bb1dc519a 100644 --- a/util-linux/rdate.c +++ b/util-linux/rdate.c | |||
| @@ -95,9 +95,13 @@ int rdate_main(int argc UNUSED_PARAM, char **argv) | |||
| 95 | if (!(flags & 2)) { /* no -p (-s may be present) */ | 95 | if (!(flags & 2)) { /* no -p (-s may be present) */ |
| 96 | if (time(NULL) == remote_time) | 96 | if (time(NULL) == remote_time) |
| 97 | bb_simple_error_msg("current time matches remote time"); | 97 | bb_simple_error_msg("current time matches remote time"); |
| 98 | else | 98 | else { |
| 99 | if (stime(&remote_time) < 0) | 99 | struct timespec ts; |
| 100 | ts.tv_sec = remote_time; | ||
| 101 | ts.tv_nsec = 0; | ||
| 102 | if (clock_settime(CLOCK_REALTIME, &ts) < 0) | ||
| 100 | bb_simple_perror_msg_and_die("can't set time of day"); | 103 | bb_simple_perror_msg_and_die("can't set time of day"); |
| 104 | } | ||
| 101 | } | 105 | } |
| 102 | 106 | ||
| 103 | if (flags != 1) /* not lone -s */ | 107 | if (flags != 1) /* not lone -s */ |
