xref: /dragonfly/lib/libcompat/4.1/ftime.c (revision 86d7f5d3)
1*86d7f5d3SJohn Marino /*
2*86d7f5d3SJohn Marino  * Copyright (c) 1994 Christopher G. Demetriou
3*86d7f5d3SJohn Marino  * All rights reserved.
4*86d7f5d3SJohn Marino  *
5*86d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino  * are met:
8*86d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer.
10*86d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
11*86d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
12*86d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
13*86d7f5d3SJohn Marino  * 3. All advertising materials mentioning features or use of this software
14*86d7f5d3SJohn Marino  *    must display the following acknowledgement:
15*86d7f5d3SJohn Marino  *      This product includes software developed by Christopher G. Demetriou.
16*86d7f5d3SJohn Marino  * 4. The name of the author may not be used to endorse or promote products
17*86d7f5d3SJohn Marino  *    derived from this software without specific prior written permission
18*86d7f5d3SJohn Marino  *
19*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20*86d7f5d3SJohn Marino  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21*86d7f5d3SJohn Marino  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22*86d7f5d3SJohn Marino  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23*86d7f5d3SJohn Marino  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24*86d7f5d3SJohn Marino  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*86d7f5d3SJohn Marino  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*86d7f5d3SJohn Marino  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*86d7f5d3SJohn Marino  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28*86d7f5d3SJohn Marino  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*86d7f5d3SJohn Marino  *
30*86d7f5d3SJohn Marino  * $FreeBSD: src/lib/libcompat/4.1/ftime.c,v 1.5 1999/08/28 00:04:12 peter Exp $
31*86d7f5d3SJohn Marino  * $DragonFly: src/lib/libcompat/4.1/ftime.c,v 1.3 2008/09/30 16:57:04 swildner Exp $
32*86d7f5d3SJohn Marino  */
33*86d7f5d3SJohn Marino 
34*86d7f5d3SJohn Marino #include <sys/types.h>
35*86d7f5d3SJohn Marino #include <sys/time.h>
36*86d7f5d3SJohn Marino #include <sys/timeb.h>
37*86d7f5d3SJohn Marino 
38*86d7f5d3SJohn Marino int
ftime(struct timeb * tbp)39*86d7f5d3SJohn Marino ftime(struct timeb *tbp)
40*86d7f5d3SJohn Marino {
41*86d7f5d3SJohn Marino         struct timezone tz;
42*86d7f5d3SJohn Marino         struct timeval t;
43*86d7f5d3SJohn Marino 
44*86d7f5d3SJohn Marino         if (gettimeofday(&t, &tz) < 0)
45*86d7f5d3SJohn Marino                 return (-1);
46*86d7f5d3SJohn Marino         tbp->millitm = t.tv_usec / 1000;
47*86d7f5d3SJohn Marino         tbp->time = t.tv_sec;
48*86d7f5d3SJohn Marino         tbp->timezone = tz.tz_minuteswest;
49*86d7f5d3SJohn Marino         tbp->dstflag = tz.tz_dsttime;
50*86d7f5d3SJohn Marino 
51*86d7f5d3SJohn Marino 	return (0);
52*86d7f5d3SJohn Marino }
53