xref: /netbsd-src/lib/libcompat/4.1/ftime.c (revision 99410184e77999def7f79bcb565a0342c7911c98)
1*99410184Ssalo /* $NetBSD: ftime.c,v 1.12 2003/07/26 19:24:55 salo Exp $ */
2d220ca5bScgd 
3a34c9134Scgd /*
4a34c9134Scgd  * Copyright (c) 1994 Christopher G. Demetriou
591ac7bf1Scgd  * All rights reserved.
691ac7bf1Scgd  *
791ac7bf1Scgd  * Redistribution and use in source and binary forms, with or without
891ac7bf1Scgd  * modification, are permitted provided that the following conditions
991ac7bf1Scgd  * are met:
1091ac7bf1Scgd  * 1. Redistributions of source code must retain the above copyright
1191ac7bf1Scgd  *    notice, this list of conditions and the following disclaimer.
1291ac7bf1Scgd  * 2. Redistributions in binary form must reproduce the above copyright
1391ac7bf1Scgd  *    notice, this list of conditions and the following disclaimer in the
1491ac7bf1Scgd  *    documentation and/or other materials provided with the distribution.
1591ac7bf1Scgd  * 3. All advertising materials mentioning features or use of this software
1691ac7bf1Scgd  *    must display the following acknowledgement:
17db755e7cScgd  *          This product includes software developed for the
18*99410184Ssalo  *          NetBSD Project.  See http://www.NetBSD.org/ for
19db755e7cScgd  *          information about NetBSD.
20a34c9134Scgd  * 4. The name of the author may not be used to endorse or promote products
21db755e7cScgd  *    derived from this software without specific prior written permission.
2291ac7bf1Scgd  *
23a34c9134Scgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24a34c9134Scgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25a34c9134Scgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26a34c9134Scgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27a34c9134Scgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28a34c9134Scgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29a34c9134Scgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30a34c9134Scgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31a34c9134Scgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32a34c9134Scgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33db755e7cScgd  *
34db755e7cScgd  * <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>>
3591ac7bf1Scgd  */
3691ac7bf1Scgd 
37e37aec67Slukem #include <sys/cdefs.h>
38a5e4741aSmsaitoh #if defined(LIBC_SCCS) && !defined(lint)
39*99410184Ssalo __RCSID("$NetBSD: ftime.c,v 1.12 2003/07/26 19:24:55 salo Exp $");
40a5e4741aSmsaitoh #endif /* LIBC_SCCS and not lint */
41aee4b07bSmycroft 
4291ac7bf1Scgd #include <sys/types.h>
4391ac7bf1Scgd #include <sys/time.h>
4491ac7bf1Scgd #include <sys/timeb.h>
4591ac7bf1Scgd 
46b48252f3Slukem #include <assert.h>
47b48252f3Slukem #include <errno.h>
48b48252f3Slukem 
49dde1c1a0Spk int
ftime(tbp)5091ac7bf1Scgd ftime(tbp)
5191ac7bf1Scgd         struct timeb *tbp;
5291ac7bf1Scgd {
5391ac7bf1Scgd         struct timezone tz;
5491ac7bf1Scgd         struct timeval t;
5591ac7bf1Scgd 
56b48252f3Slukem 	_DIAGASSERT(tbp != 0);
57b48252f3Slukem 
5891ac7bf1Scgd         if (gettimeofday(&t, &tz) < 0)
5991ac7bf1Scgd                 return (-1);
60d2cc1353Schristos         tbp->millitm = (unsigned short)(t.tv_usec / 1000);
6191ac7bf1Scgd         tbp->time = t.tv_sec;
6291ac7bf1Scgd         tbp->timezone = tz.tz_minuteswest;
6391ac7bf1Scgd         tbp->dstflag = tz.tz_dsttime;
6491ac7bf1Scgd 
6591ac7bf1Scgd 	return (0);
6691ac7bf1Scgd }
67