/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* David Korn <dgk@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Research
*
* Tv_t conversion support
*/
#if defined(__STDPP__directive) && defined(__STDPP__hide)
#else
#define utime ______utime
#endif
#ifndef _ATFILE_SOURCE
#endif
#include <ast.h>
#include <ls.h>
#include <tv.h>
#include <times.h>
#include <error.h>
#if _hdr_utime && _lib_utime
#include <utime.h>
#endif
#if defined(__STDPP__directive) && defined(__STDPP__hide)
#else
#endif
#if _lib_utime
#if _hdr_utime
#else
#endif
#endif
/*
* touch path <atime,mtime,ctime>
* Tv_t==0 uses current time
* Tv_t==TV_TOUCH_RETAIN retains path value if it exists, current time otherwise
* otherwise it is exact time
* file created if it doesn't exist and (flags&TV_TOUCH_CREATE)
* symlink not followed if (flags&TV_TOUCH_PHYSICAL)
* cv most likely ignored on most implementations
*
* NOTE: when *at() calls are integrated TV_TOUCH_* should be advertized!
*/
#endif
int
tvtouch(const char* path, register const Tv_t* av, register const Tv_t* mv, const Tv_t* cv, int flags)
{
int fd;
int mode;
int oerrno;
#if _lib_utimets || _lib_utimensat
#endif
#if _lib_utimes
#else
#if _hdr_utime
#else
#endif
#endif
#if _lib_utimensat
if (!av)
{
}
else if (av == TV_TOUCH_RETAIN)
{
}
else
{
}
if (!mv)
{
}
else if (mv == TV_TOUCH_RETAIN)
{
}
else
{
}
if (!cv && av == TV_TOUCH_RETAIN && mv == TV_TOUCH_RETAIN && !stat(path, &st) && !chmod(path, st.st_mode & S_IPERM))
return 0;
if (!utimensat(AT_FDCWD, path, ts[0].tv_nsec == UTIME_NOW && ts[1].tv_nsec == UTIME_NOW ? (struct timespec*)0 : ts, (flags & TV_TOUCH_PHYSICAL) ? AT_SYMLINK_NOFOLLOW : 0))
return 0;
{
return -1;
return -1;
if ((ts[0].tv_nsec != UTIME_NOW || ts[1].tv_nsec != UTIME_NOW) && utimensat(AT_FDCWD, path, ts, (flags & TV_TOUCH_PHYSICAL) ? AT_SYMLINK_NOFOLLOW : 0))
return -1;
return 0;
}
#endif
{
if (av == TV_TOUCH_RETAIN)
av = 0;
if (mv == TV_TOUCH_RETAIN)
mv = 0;
}
{
if (!av)
if (!mv)
}
#if _lib_utimets
if (av == TV_TOUCH_RETAIN)
{
}
else
{
}
if (mv == TV_TOUCH_RETAIN)
{
}
else
{
}
return 0;
{
return 0;
}
#else
#if _lib_utimes
if (av == TV_TOUCH_RETAIN)
{
}
else
{
}
if (mv == TV_TOUCH_RETAIN)
{
}
else
{
}
return 0;
{
return 0;
}
#else
#if _lib_utime
return 0;
#if _lib_utime_now
{
return 0;
}
#endif
#endif
#endif
{
{
return -1;
}
{
char c;
{
if (c)
return 0;
}
}
}
#endif
return -1;
return -1;
return 0;
#if _lib_utimets
#else
#if _lib_utimes
#else
#if _lib_utime
#else
return -1;
#endif
#endif
#endif
}