xref: /minix3/minix/lib/libc/sys/utimes.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #include <sys/cdefs.h>
2*433d6423SLionel Sambuc #include "namespace.h"
3*433d6423SLionel Sambuc #include <lib.h>
4*433d6423SLionel Sambuc 
5*433d6423SLionel Sambuc #include <sys/stat.h>
6*433d6423SLionel Sambuc #include <sys/time.h>
7*433d6423SLionel Sambuc #include <string.h>
8*433d6423SLionel Sambuc #include <errno.h>
9*433d6423SLionel Sambuc 
10*433d6423SLionel Sambuc #ifdef __weak_alias
__weak_alias(utimes,__utimes50)11*433d6423SLionel Sambuc __weak_alias(utimes, __utimes50)
12*433d6423SLionel Sambuc #endif
13*433d6423SLionel Sambuc 
14*433d6423SLionel Sambuc int utimes(const char *name, const struct timeval tv[2])
15*433d6423SLionel Sambuc {
16*433d6423SLionel Sambuc   message m;
17*433d6423SLionel Sambuc 
18*433d6423SLionel Sambuc   if (name == NULL) {
19*433d6423SLionel Sambuc 	errno = EINVAL;
20*433d6423SLionel Sambuc 	return -1;
21*433d6423SLionel Sambuc   }
22*433d6423SLionel Sambuc   if (name[0] == '\0') { /* X/Open requirement */
23*433d6423SLionel Sambuc 	errno = ENOENT;
24*433d6423SLionel Sambuc 	return -1;
25*433d6423SLionel Sambuc   }
26*433d6423SLionel Sambuc   memset(&m, 0, sizeof(m));
27*433d6423SLionel Sambuc   m.m_vfs_utimens.len = strlen(name) + 1;
28*433d6423SLionel Sambuc   m.m_vfs_utimens.name = __UNCONST(name);
29*433d6423SLionel Sambuc   if (tv == NULL) {
30*433d6423SLionel Sambuc 	m.m_vfs_utimens.atime = m.m_vfs_utimens.mtime = 0;
31*433d6423SLionel Sambuc 	m.m_vfs_utimens.ansec = m.m_vfs_utimens.mnsec = UTIME_NOW;
32*433d6423SLionel Sambuc   }
33*433d6423SLionel Sambuc   else {
34*433d6423SLionel Sambuc 	m.m_vfs_utimens.atime = tv[0].tv_sec;
35*433d6423SLionel Sambuc 	m.m_vfs_utimens.mtime = tv[1].tv_sec;
36*433d6423SLionel Sambuc 	m.m_vfs_utimens.ansec = tv[0].tv_usec * 1000;
37*433d6423SLionel Sambuc 	m.m_vfs_utimens.mnsec = tv[1].tv_usec * 1000;
38*433d6423SLionel Sambuc   }
39*433d6423SLionel Sambuc   m.m_vfs_utimens.flags = 0;
40*433d6423SLionel Sambuc 
41*433d6423SLionel Sambuc   return(_syscall(VFS_PROC_NR, VFS_UTIMENS, &m));
42*433d6423SLionel Sambuc }
43