OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [userland/] [sash/] [date.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/* date.c bradkemp@indusriver.com */
2
 
3
#include <time.h>
4
#include <stdio.h>
5
 
6
static const char invalid_date[] = "Invalid date %s\n";
7
int do_date(int argc, char * argv[])
8
{
9
 
10
    time_t tm;
11
    struct tm tm_time;
12
    time(&tm);
13
    memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
14
 
15
    if (argc > 1) {
16
        int nr;
17
 
18
        nr = sscanf(argv[1], "%2d%2d%2d%2d%d",
19
                    &(tm_time.tm_mon),
20
                    &(tm_time.tm_mday),
21
                    &(tm_time.tm_hour),
22
                    &(tm_time.tm_min), &(tm_time.tm_year));
23
 
24
        if (nr < 4 || nr > 5) {
25
            fprintf(stderr, invalid_date, argv[1]);
26
            return(0);
27
        }
28
 
29
        /* correct for century  - minor Y2K problem here? */
30
        if (tm_time.tm_year >= 1900)
31
            tm_time.tm_year -= 1900;
32
        /* adjust date */
33
        tm_time.tm_mon -= 1;
34
 
35
        if((tm = mktime(&tm_time)) < 0) {
36
            fprintf(stderr, invalid_date, argv[1]);
37
            return(0);
38
        }
39
 
40
        if(stime(&tm) < 0) {
41
            fprintf(stderr, "Unable to set date\n");
42
            return(0);
43
        }
44
 
45
        return (0);
46
 
47
    }
48
    printf("%s\n",asctime(&tm_time));
49
 
50
    return(0);
51
}
52
 
53
 
54
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.