40 |
|
#endif |
41 |
|
|
42 |
|
#include <sys/cdefs.h> |
43 |
< |
__FBSDID("$FreeBSD: release/7.0.0/bin/date/date.c 139969 2005-01-10 08:39:26Z imp $"); |
43 |
> |
__FBSDID("$FreeBSD$"); |
44 |
|
|
45 |
|
#include <sys/param.h> |
46 |
|
#include <sys/time.h> |
48 |
|
#include <ctype.h> |
49 |
|
#include <err.h> |
50 |
|
#include <locale.h> |
51 |
– |
#include <libutil.h> |
51 |
|
#include <stdio.h> |
52 |
|
#include <stdlib.h> |
53 |
|
#include <string.h> |
54 |
|
#include <syslog.h> |
55 |
|
#include <unistd.h> |
56 |
+ |
#include <utmpx.h> |
57 |
|
|
58 |
|
#include "extern.h" |
59 |
|
#include "vary.h" |
181 |
|
static void |
182 |
|
setthetime(const char *fmt, const char *p, int jflag, int nflag) |
183 |
|
{ |
184 |
+ |
struct utmpx utx; |
185 |
|
struct tm *lt; |
186 |
|
struct timeval tv; |
187 |
|
const char *dot, *t; |
188 |
|
int century; |
189 |
|
|
190 |
+ |
lt = localtime(&tval); |
191 |
+ |
lt->tm_isdst = -1; /* divine correct DST */ |
192 |
+ |
|
193 |
|
if (fmt != NULL) { |
190 |
– |
lt = localtime(&tval); |
194 |
|
t = strptime(p, fmt, lt); |
195 |
|
if (t == NULL) { |
196 |
|
fprintf(stderr, "Failed conversion of ``%s''" |
211 |
|
badformat(); |
212 |
|
} |
213 |
|
|
211 |
– |
lt = localtime(&tval); |
212 |
– |
|
214 |
|
if (dot != NULL) { /* .ss */ |
215 |
|
dot++; /* *dot++ = '\0'; */ |
216 |
|
if (strlen(dot) != 2) |
265 |
|
} |
266 |
|
} |
267 |
|
|
267 |
– |
/* Let mktime() decide whether summer time is in effect. */ |
268 |
– |
lt->tm_isdst = -1; |
269 |
– |
|
268 |
|
/* convert broken-down time to GMT clock time */ |
269 |
|
if ((tval = mktime(lt)) == -1) |
270 |
|
errx(1, "nonexistent time"); |
272 |
|
if (!jflag) { |
273 |
|
/* set the time */ |
274 |
|
if (nflag || netsettime(tval)) { |
275 |
< |
logwtmp("|", "date", ""); |
275 |
> |
utx.ut_type = OLD_TIME; |
276 |
> |
gettimeofday(&utx.ut_tv, NULL); |
277 |
> |
pututxline(&utx); |
278 |
|
tv.tv_sec = tval; |
279 |
|
tv.tv_usec = 0; |
280 |
|
if (settimeofday(&tv, (struct timezone *)NULL)) |
281 |
|
err(1, "settimeofday (timeval)"); |
282 |
< |
logwtmp("{", "date", ""); |
282 |
> |
utx.ut_type = NEW_TIME; |
283 |
> |
gettimeofday(&utx.ut_tv, NULL); |
284 |
> |
pututxline(&utx); |
285 |
|
} |
286 |
|
|
287 |
|
if ((p = getlogin()) == NULL) |