1/*
2 * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
3 * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license.  For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7
8The asctime() function shall convert the broken-down time in the structure pointed to by timeptr into a string in the form: Sun Sep 16 01:03:52 1973\n\0
9
10 */
11
12#define WEEKDAY 0
13#define MONTH 8
14#define MONTHDAY 16
15#define HOUR 1
16#define MINUTE 3
17#define SECOND 52
18#define YEAR 73
19
20#include <string.h>
21#include <time.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <unistd.h>
25#include "posixtest.h"
26
27int main(void)
28{
29	struct tm time_ptr;
30
31	char expected[26];
32	char *real;
33
34	char wday_name[7][3] =
35	    { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
36
37	char mon_name[12][3] = {
38		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
39		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
40	};
41
42	time_ptr.tm_wday = WEEKDAY;
43	time_ptr.tm_mon = MONTH;
44	time_ptr.tm_mday = MONTHDAY;
45	time_ptr.tm_hour = HOUR;
46	time_ptr.tm_min = MINUTE;
47	time_ptr.tm_sec = SECOND;
48	time_ptr.tm_year = YEAR;
49
50	real = asctime(&time_ptr);
51
52	sprintf(expected, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
53		wday_name[time_ptr.tm_wday],
54		mon_name[time_ptr.tm_mon],
55		time_ptr.tm_mday, time_ptr.tm_hour,
56		time_ptr.tm_min, time_ptr.tm_sec, 1900 + time_ptr.tm_year);
57
58	printf("real = %s\n", real);
59	printf("expected = %s\n", expected);
60
61	if (strcmp(real, expected) != 0) {
62		perror("asctime did not return the correct value\n");
63		printf("Got %s\n", real);
64		printf("Expected %s\n", expected);
65		return PTS_FAIL;
66	}
67
68	printf("Test PASSED\n");
69	return PTS_PASS;
70}
71