diff options
-rw-r--r-- | util-linux/hwclock.c | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 126caf6be..5992d8420 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c | |||
@@ -4,20 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2002 Robert Griebl <griebl@gmx.de> | 5 | * Copyright (C) 2002 Robert Griebl <griebl@gmx.de> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | 8 | */ |
22 | 9 | ||
23 | 10 | ||
@@ -70,7 +57,7 @@ static time_t read_rtc(int utc) | |||
70 | memset ( &tm, 0, sizeof( struct tm )); | 57 | memset ( &tm, 0, sizeof( struct tm )); |
71 | if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 ) | 58 | if ( ioctl ( rtc, RTC_RD_TIME, &tm ) < 0 ) |
72 | bb_perror_msg_and_die ( "Could not read time from RTC" ); | 59 | bb_perror_msg_and_die ( "Could not read time from RTC" ); |
73 | tm. tm_isdst = -1; // not known | 60 | tm.tm_isdst = -1; /* not known */ |
74 | 61 | ||
75 | close ( rtc ); | 62 | close ( rtc ); |
76 | 63 | ||
@@ -103,7 +90,7 @@ static void write_rtc(time_t t, int utc) | |||
103 | } | 90 | } |
104 | 91 | ||
105 | tm = *( utc ? gmtime ( &t ) : localtime ( &t )); | 92 | tm = *( utc ? gmtime ( &t ) : localtime ( &t )); |
106 | tm. tm_isdst = 0; | 93 | tm.tm_isdst = 0; |
107 | 94 | ||
108 | if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) | 95 | if ( ioctl ( rtc, RTC_SET_TIME, &tm ) < 0 ) |
109 | bb_perror_msg_and_die ( "Could not set the RTC time" ); | 96 | bb_perror_msg_and_die ( "Could not set the RTC time" ); |
@@ -115,17 +102,18 @@ static int show_clock(int utc) | |||
115 | { | 102 | { |
116 | struct tm *ptm; | 103 | struct tm *ptm; |
117 | time_t t; | 104 | time_t t; |
118 | char buffer [64]; | 105 | RESERVE_CONFIG_BUFFER(buffer, 64); |
119 | 106 | ||
120 | t = read_rtc ( utc ); | 107 | t = read_rtc ( utc ); |
121 | ptm = localtime ( &t ); /* Sets 'tzname[]' */ | 108 | ptm = localtime ( &t ); /* Sets 'tzname[]' */ |
122 | 109 | ||
123 | safe_strncpy ( buffer, ctime ( &t ), sizeof( buffer )); | 110 | safe_strncpy ( buffer, ctime ( &t ), 64); |
124 | if ( buffer [0] ) | 111 | if ( buffer [0] ) |
125 | buffer [bb_strlen ( buffer ) - 1] = 0; | 112 | buffer [bb_strlen ( buffer ) - 1] = 0; |
126 | 113 | ||
127 | //printf ( "%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : ( ptm-> tm_isdst ? tzname [1] : tzname [0] )); | 114 | //printf ( "%s %.6f seconds %s\n", buffer, 0.0, utc ? "" : ( ptm-> tm_isdst ? tzname [1] : tzname [0] )); |
128 | printf ( "%s %.6f seconds\n", buffer, 0.0 ); | 115 | printf ( "%s %.6f seconds\n", buffer, 0.0 ); |
116 | RELEASE_CONFIG_BUFFER(buffer); | ||
129 | 117 | ||
130 | return 0; | 118 | return 0; |
131 | } | 119 | } |
@@ -135,7 +123,7 @@ static int to_sys_clock(int utc) | |||
135 | struct timeval tv = { 0, 0 }; | 123 | struct timeval tv = { 0, 0 }; |
136 | const struct timezone tz = { timezone/60 - 60*daylight, 0 }; | 124 | const struct timezone tz = { timezone/60 - 60*daylight, 0 }; |
137 | 125 | ||
138 | tv. tv_sec = read_rtc ( utc ); | 126 | tv.tv_sec = read_rtc ( utc ); |
139 | 127 | ||
140 | if ( settimeofday ( &tv, &tz )) | 128 | if ( settimeofday ( &tv, &tz )) |
141 | bb_perror_msg_and_die ( "settimeofday() failed" ); | 129 | bb_perror_msg_and_die ( "settimeofday() failed" ); |
@@ -151,7 +139,7 @@ static int from_sys_clock(int utc) | |||
151 | if ( gettimeofday ( &tv, &tz )) | 139 | if ( gettimeofday ( &tv, &tz )) |
152 | bb_perror_msg_and_die ( "gettimeofday() failed" ); | 140 | bb_perror_msg_and_die ( "gettimeofday() failed" ); |
153 | 141 | ||
154 | write_rtc ( tv. tv_sec, utc ); | 142 | write_rtc ( tv.tv_sec, utc ); |
155 | return 0; | 143 | return 0; |
156 | } | 144 | } |
157 | 145 | ||
@@ -166,7 +154,7 @@ static int check_utc(void) | |||
166 | FILE *f = fopen ( ADJTIME_PATH, "r" ); | 154 | FILE *f = fopen ( ADJTIME_PATH, "r" ); |
167 | 155 | ||
168 | if ( f ) { | 156 | if ( f ) { |
169 | char buffer [128]; | 157 | RESERVE_CONFIG_BUFFER(buffer, 128); |
170 | 158 | ||
171 | while ( fgets ( buffer, sizeof( buffer ), f )) { | 159 | while ( fgets ( buffer, sizeof( buffer ), f )) { |
172 | int len = bb_strlen ( buffer ); | 160 | int len = bb_strlen ( buffer ); |
@@ -182,6 +170,7 @@ static int check_utc(void) | |||
182 | } | 170 | } |
183 | } | 171 | } |
184 | fclose ( f ); | 172 | fclose ( f ); |
173 | RELEASE_CONFIG_BUFFER(buffer); | ||
185 | } | 174 | } |
186 | return utc; | 175 | return utc; |
187 | } | 176 | } |