From 7ba82a29882b6382e449cecc0009e58de0b042e8 Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Fri, 29 May 2009 14:51:26 +0000 Subject: [PATCH] Add default path for iso8601_leap_table_load() --- config | 2 ++ src/libiso8601/100_leap.c | 2 ++ src/libiso8601/400_leap.h | 6 ++++-- src/libiso8601/build.lib | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/config b/config index 8c6771c..8382c24 100644 --- a/config +++ b/config @@ -32,5 +32,7 @@ source "scripts/paths" # Project-specific variables below. +[ -z "${DEFAULT_LEAP_TABLE}" ] && DEFAULT_LEAP_TABLE="${SHAREDIR}/libiso8601/leap-table" + [ -z "${CC}" ] && CC="gcc" [ -z "${CFLAGS}" ] && CFLAGS="-g -O2 -W -Wall" diff --git a/src/libiso8601/100_leap.c b/src/libiso8601/100_leap.c index 20647de..cdba1a7 100644 --- a/src/libiso8601/100_leap.c +++ b/src/libiso8601/100_leap.c @@ -96,6 +96,8 @@ int iso8601_leap_table_load(const char* fname) int fd, saved_errno, i, new_size, * days = 0; char buf[12]; + if(!fname) fname = DEFAULT_LEAP_TABLE; + if(stat(fname, &st)) return -1; if(st.st_size < 12) { errno = EINVAL; diff --git a/src/libiso8601/400_leap.h b/src/libiso8601/400_leap.h index 05304ca..e090b80 100644 --- a/src/libiso8601/400_leap.h +++ b/src/libiso8601/400_leap.h @@ -91,17 +91,19 @@ void iso8601_leap_table_set(int* new_table, int new_size) __attribute__((nonnull /*! \brief Load new table of leap seconds from disk. -\param fname Filename. +\param fname Filename. May be 0 for system default. \retval 0 on success. \retval -1 on error (and see \a errno). This function attempts to load a new table of leap seconds from disk, using the filename \a fname. +If \a fname is not specified, the system default (set at compile time) will be used. + If the table is loaded successfully, it will be set with \ref iso8601_leap_table_set(). On any error, -1 will be returned, and \a errno will be set appropriately. If \a errno is \c EINVAL, then the file does not contain a valid leap second table. */ -int iso8601_leap_table_load(const char* fname) __attribute__((nonnull)); +int iso8601_leap_table_load(const char* fname); diff --git a/src/libiso8601/build.lib b/src/libiso8601/build.lib index 080592f..3937758 100644 --- a/src/libiso8601/build.lib +++ b/src/libiso8601/build.lib @@ -14,7 +14,7 @@ then libiso8601="obj/${libiso8601_BASE}.so.${SOMAJOR}.${SOMICRO}" libiso8601_DEP_CFLAGS="" libiso8601_DEP_LIBS="-lrt" - SO_EXTRA="-std=gnu99 -D_GNU_SOURCE ${libiso8601_DEP_CFLAGS} ${libiso8601_DEP_LIBS} -lc" + SO_EXTRA="-std=gnu99 -D_GNU_SOURCE -DDEFAULT_LEAP_TABLE=\"${DEFAULT_LEAP_TABLE}\" ${libiso8601_DEP_CFLAGS} ${libiso8601_DEP_LIBS} -lc" echo "Building library ${libiso8601}..."