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