tmxtouch.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett/***********************************************************************
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder* *
e071fb22ea9923a2a4ff41184d80ca46b55ee932Till Mossakowski* This software is part of the ast package *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Copyright (c) 1985-2011 AT&T Intellectual Property *
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu* and is licensed under the *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Eclipse Public License, Version 1.0 *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* by AT&T Intellectual Property *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* A copy of the License is available at *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* http://www.eclipse.org/org/documents/epl-v10.html *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Information and Software Systems Research *
9ebbce450fb242e1a346f9f89367d8c46fcb2ec8Andy Gimblett* AT&T Research *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Florham Park NJ *
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly* *
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder* Glenn Fowler <gsf@research.att.com> *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* David Korn <dgk@research.att.com> *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Phong Vo <kpv@research.att.com> *
05b3e12808da901dccd665715cb934462290d550Andy Gimblett* *
9ebbce450fb242e1a346f9f89367d8c46fcb2ec8Andy Gimblett***********************************************************************/
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblett#pragma prototyped
aa0d5f8be9950e788884f7431cf4cb7bee74788cAndy Gimblett/*
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly * Glenn Fowler
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett * AT&T Research
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder *
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder * Time_t conversion support
567db7182e691cce5816365d8c912d09ffe92f86Andy Gimblett */
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder#include <tmx.h>
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder#include <tv.h>
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder/*
8db2221917c1bc569614f3481bcdb3b988facaedChristian Maeder * touch path <atime,mtime,ctime>
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder * (flags&PATH_TOUCH_VERBATIM) treats times verbatim, otherwise:
8db2221917c1bc569614f3481bcdb3b988facaedChristian Maeder * Time_t==0 current time
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder * Time_t==TMX_NOTIME retains path value
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett */
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reillyint
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reillytmxtouch(const char* path, Time_t at, Time_t mt, Time_t ct, int flags)
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder{
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder Tv_t av;
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder Tv_t mv;
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder Tv_t cv;
dd7da1b5fedc05b92ba023ebd803e6f4a662503bChristian Maeder Tv_t* ap;
dd7da1b5fedc05b92ba023ebd803e6f4a662503bChristian Maeder Tv_t* mp;
dd7da1b5fedc05b92ba023ebd803e6f4a662503bChristian Maeder Tv_t* cp;
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder if (at == TMX_NOTIME && !(flags & PATH_TOUCH_VERBATIM))
dd7da1b5fedc05b92ba023ebd803e6f4a662503bChristian Maeder ap = TV_TOUCH_RETAIN;
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder else if (!at && !(flags & PATH_TOUCH_VERBATIM))
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly ap = 0;
0b8146e4f675518993a34eb2255ad7ddd7bf82a4Christian Maeder else
23a073e0a3433ca80a286d46202841b569ec36fdChristian Maeder {
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'Reilly av.tv_sec = tmxsec(at);
05cc55892e6c93bdd7b9c3f100ab1bb65fe6a21eLiam O'Reilly av.tv_nsec = tmxnsec(at);
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett ap = &av;
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett }
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett if (mt == TMX_NOTIME && !(flags & PATH_TOUCH_VERBATIM))
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett mp = TV_TOUCH_RETAIN;
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett else if (!mt && !(flags & PATH_TOUCH_VERBATIM))
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett mp = 0;
12b2ae689353ecbaad720a9af9f9be01c1a3fe2dChristian Maeder else
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett {
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett mv.tv_sec = tmxsec(mt);
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett mv.tv_nsec = tmxnsec(mt);
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett mp = &mv;
b25c72845890740c2f8a21214752574990b943cfChristian Maeder }
b25c72845890740c2f8a21214752574990b943cfChristian Maeder if (ct == TMX_NOTIME && !(flags & PATH_TOUCH_VERBATIM))
b25c72845890740c2f8a21214752574990b943cfChristian Maeder cp = TV_TOUCH_RETAIN;
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett else if (!ct && !(flags & PATH_TOUCH_VERBATIM))
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett cp = 0;
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian Maeder else
dfc58f5ec6492d1a9b9babd9cdcdbb15baa6e657Christian Maeder {
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian Maeder cv.tv_sec = tmxsec(ct);
a5f3a8cdc3ceb045c3c166ee840d3e59ec7efac6Christian Maeder cv.tv_nsec = tmxnsec(ct);
dfc58f5ec6492d1a9b9babd9cdcdbb15baa6e657Christian Maeder cp = &cv;
b25c72845890740c2f8a21214752574990b943cfChristian Maeder }
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett return tvtouch(path, ap, mp, cp, flags & 1);
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett}
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett