2008-05-05 12:35:38 +04:00
|
|
|
/*
|
|
|
|
* libcsync -- a library to sync a directory with another
|
|
|
|
*
|
2013-07-23 19:31:55 +04:00
|
|
|
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
|
2008-05-05 12:35:38 +04:00
|
|
|
*
|
2013-07-23 19:31:55 +04:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2008-05-05 12:35:38 +04:00
|
|
|
*
|
2013-07-23 19:31:55 +04:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2008-05-05 12:35:38 +04:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2013-07-23 19:31:55 +04:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2008-05-05 12:35:38 +04:00
|
|
|
*
|
2013-07-23 19:31:55 +04:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-05-05 12:35:38 +04:00
|
|
|
*/
|
|
|
|
|
2014-01-15 15:20:03 +04:00
|
|
|
#include "config_csync.h"
|
2012-03-02 19:47:34 +04:00
|
|
|
|
2008-05-05 12:35:38 +04:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include "csync_time.h"
|
|
|
|
#include "vio/csync_vio.h"
|
|
|
|
|
|
|
|
#define CSYNC_LOG_CATEGORY_NAME "csync.time"
|
|
|
|
#include "csync_log.h"
|
|
|
|
|
2012-02-04 17:24:22 +04:00
|
|
|
#ifdef HAVE_CLOCK_GETTIME
|
|
|
|
# ifdef _POSIX_MONOTONIC_CLOCK
|
|
|
|
# define CSYNC_CLOCK CLOCK_MONOTONIC
|
|
|
|
# else
|
|
|
|
# define CSYNC_CLOCK CLOCK_REALTIME
|
|
|
|
# endif
|
2012-02-04 16:09:07 +04:00
|
|
|
#endif
|
2012-04-17 14:31:27 +04:00
|
|
|
|
2012-02-04 16:09:07 +04:00
|
|
|
|
|
|
|
int csync_gettime(struct timespec *tp)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_CLOCK_GETTIME
|
2012-02-04 17:24:22 +04:00
|
|
|
return clock_gettime(CSYNC_CLOCK, tp);
|
2012-02-04 16:09:07 +04:00
|
|
|
#else
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
if (gettimeofday(&tv, NULL) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tp->tv_sec = tv.tv_sec;
|
|
|
|
tp->tv_nsec = tv.tv_usec * 1000;
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CSYNC_CLOCK
|
|
|
|
|
2009-05-13 12:12:07 +04:00
|
|
|
/* vim: set ts=8 sw=2 et cindent: */
|