xref: /freebsd/cddl/contrib/opensolaris/cmd/stat/common/timestamp.c (revision 10b9d77bf1ccf2f3affafa6261692cb92cf7e992)
1*10b9d77bSPawel Jakub Dawidek /*
2*10b9d77bSPawel Jakub Dawidek  * CDDL HEADER START
3*10b9d77bSPawel Jakub Dawidek  *
4*10b9d77bSPawel Jakub Dawidek  * The contents of this file are subject to the terms of the
5*10b9d77bSPawel Jakub Dawidek  * Common Development and Distribution License (the "License").
6*10b9d77bSPawel Jakub Dawidek  * You may not use this file except in compliance with the License.
7*10b9d77bSPawel Jakub Dawidek  *
8*10b9d77bSPawel Jakub Dawidek  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*10b9d77bSPawel Jakub Dawidek  * or http://www.opensolaris.org/os/licensing.
10*10b9d77bSPawel Jakub Dawidek  * See the License for the specific language governing permissions
11*10b9d77bSPawel Jakub Dawidek  * and limitations under the License.
12*10b9d77bSPawel Jakub Dawidek  *
13*10b9d77bSPawel Jakub Dawidek  * When distributing Covered Code, include this CDDL HEADER in each
14*10b9d77bSPawel Jakub Dawidek  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*10b9d77bSPawel Jakub Dawidek  * If applicable, add the following below this CDDL HEADER, with the
16*10b9d77bSPawel Jakub Dawidek  * fields enclosed by brackets "[]" replaced with your own identifying
17*10b9d77bSPawel Jakub Dawidek  * information: Portions Copyright [yyyy] [name of copyright owner]
18*10b9d77bSPawel Jakub Dawidek  *
19*10b9d77bSPawel Jakub Dawidek  * CDDL HEADER END
20*10b9d77bSPawel Jakub Dawidek  */
21*10b9d77bSPawel Jakub Dawidek /*
22*10b9d77bSPawel Jakub Dawidek  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*10b9d77bSPawel Jakub Dawidek  * Use is subject to license terms.
24*10b9d77bSPawel Jakub Dawidek  */
25*10b9d77bSPawel Jakub Dawidek 
26*10b9d77bSPawel Jakub Dawidek #include "statcommon.h"
27*10b9d77bSPawel Jakub Dawidek 
28*10b9d77bSPawel Jakub Dawidek #include <langinfo.h>
29*10b9d77bSPawel Jakub Dawidek 
30*10b9d77bSPawel Jakub Dawidek /*
31*10b9d77bSPawel Jakub Dawidek  * Print timestamp as decimal reprentation of time_t value (-T u was specified)
32*10b9d77bSPawel Jakub Dawidek  * or in date(1) format (-T d was specified).
33*10b9d77bSPawel Jakub Dawidek  */
34*10b9d77bSPawel Jakub Dawidek void
print_timestamp(uint_t timestamp_fmt)35*10b9d77bSPawel Jakub Dawidek print_timestamp(uint_t timestamp_fmt)
36*10b9d77bSPawel Jakub Dawidek {
37*10b9d77bSPawel Jakub Dawidek 	time_t t = time(NULL);
38*10b9d77bSPawel Jakub Dawidek 
39*10b9d77bSPawel Jakub Dawidek 	if (timestamp_fmt == UDATE) {
40*10b9d77bSPawel Jakub Dawidek 		(void) printf("%ld\n", t);
41*10b9d77bSPawel Jakub Dawidek 	} else if (timestamp_fmt == DDATE) {
42*10b9d77bSPawel Jakub Dawidek 		char dstr[64];
43*10b9d77bSPawel Jakub Dawidek 		int len;
44*10b9d77bSPawel Jakub Dawidek 
45*10b9d77bSPawel Jakub Dawidek 		len = strftime(dstr, sizeof (dstr), "%+", localtime(&t));
46*10b9d77bSPawel Jakub Dawidek 		if (len > 0)
47*10b9d77bSPawel Jakub Dawidek 			(void) printf("%s\n", dstr);
48*10b9d77bSPawel Jakub Dawidek 	}
49*10b9d77bSPawel Jakub Dawidek }
50