xref: /netbsd-src/lib/libc/compat/gen/compat_utime.c (revision 461a86f9bdbf4658bc4b37796e978427095f94a7)
1*461a86f9Schristos /*	$NetBSD: compat_utime.c,v 1.2 2009/01/11 02:46:25 christos Exp $	*/
2*461a86f9Schristos 
3*461a86f9Schristos /*-
4*461a86f9Schristos  * Copyright (c) 1990, 1993
5*461a86f9Schristos  *	The Regents of the University of California.  All rights reserved.
6*461a86f9Schristos  *
7*461a86f9Schristos  * Redistribution and use in source and binary forms, with or without
8*461a86f9Schristos  * modification, are permitted provided that the following conditions
9*461a86f9Schristos  * are met:
10*461a86f9Schristos  * 1. Redistributions of source code must retain the above copyright
11*461a86f9Schristos  *    notice, this list of conditions and the following disclaimer.
12*461a86f9Schristos  * 2. Redistributions in binary form must reproduce the above copyright
13*461a86f9Schristos  *    notice, this list of conditions and the following disclaimer in the
14*461a86f9Schristos  *    documentation and/or other materials provided with the distribution.
15*461a86f9Schristos  * 3. Neither the name of the University nor the names of its contributors
16*461a86f9Schristos  *    may be used to endorse or promote products derived from this software
17*461a86f9Schristos  *    without specific prior written permission.
18*461a86f9Schristos  *
19*461a86f9Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*461a86f9Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*461a86f9Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*461a86f9Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*461a86f9Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*461a86f9Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*461a86f9Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*461a86f9Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*461a86f9Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*461a86f9Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*461a86f9Schristos  * SUCH DAMAGE.
30*461a86f9Schristos  */
31*461a86f9Schristos 
32*461a86f9Schristos #include <sys/cdefs.h>
33*461a86f9Schristos #if defined(LIBC_SCCS) && !defined(lint)
34*461a86f9Schristos #if 0
35*461a86f9Schristos static char sccsid[] = "@(#)utime.c	8.1 (Berkeley) 6/4/93";
36*461a86f9Schristos #else
37*461a86f9Schristos __RCSID("$NetBSD: compat_utime.c,v 1.2 2009/01/11 02:46:25 christos Exp $");
38*461a86f9Schristos #endif
39*461a86f9Schristos #endif /* LIBC_SCCS and not lint */
40*461a86f9Schristos 
41*461a86f9Schristos 
42*461a86f9Schristos #define __LIBC12_SOURCE__
43*461a86f9Schristos 
44*461a86f9Schristos #include "namespace.h"
45*461a86f9Schristos #include <assert.h>
46*461a86f9Schristos #include <errno.h>
47*461a86f9Schristos #include <stddef.h>
48*461a86f9Schristos #include <stdint.h>
49*461a86f9Schristos #include <utime.h>
50*461a86f9Schristos #include <compat/include/utime.h>
51*461a86f9Schristos #include <sys/time.h>
52*461a86f9Schristos #include <compat/sys/time.h>
53*461a86f9Schristos 
54*461a86f9Schristos __warn_references(utime,
55*461a86f9Schristos     "warning: reference to compatibility utime(); include <utime.h> to generate correct reference")
56*461a86f9Schristos 
57*461a86f9Schristos #ifdef __weak_alias
__weak_alias(utime,_utime)58*461a86f9Schristos __weak_alias(utime, _utime)
59*461a86f9Schristos #endif
60*461a86f9Schristos 
61*461a86f9Schristos int
62*461a86f9Schristos utime(const char *path, const struct utimbuf50 *times50)
63*461a86f9Schristos {
64*461a86f9Schristos 	struct timeval tv[2], *tvp;
65*461a86f9Schristos 
66*461a86f9Schristos 	_DIAGASSERT(path != NULL);
67*461a86f9Schristos 
68*461a86f9Schristos 	if (times50 == NULL)
69*461a86f9Schristos 		tvp = NULL;
70*461a86f9Schristos 	else {
71*461a86f9Schristos 		tv[0].tv_sec = times50->actime;
72*461a86f9Schristos 		tv[1].tv_sec = times50->modtime;
73*461a86f9Schristos 		tv[0].tv_usec = tv[1].tv_usec = 0;
74*461a86f9Schristos 		tvp = tv;
75*461a86f9Schristos 	}
76*461a86f9Schristos 	return __utimes50(path, tvp);
77*461a86f9Schristos }
78