nextcloud-desktop/csync/src/csync_time.c

66 lines
1.6 KiB
C
Raw Normal View History

/*
* libcsync -- a library to sync a directory with another
*
* Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
*
* 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.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* 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
*/
#include "config_csync.h"
2012-03-02 19:47:34 +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-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: */