From 5f3629bea0d4beb79c6092086b46f3d73643c76d Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 7 Sep 2011 10:21:47 -0500 Subject: Introduce alpm_time_t type This will always be a 64-bit signed integer rather than the variable length time_t type. Dates beyond 2038 should be fully supported in the library; the frontend still lags behind because 32-bit platforms provide no localtime64() or equivalent function to convert from an epoch value to a broken down time structure. Signed-off-by: Dan McGee --- lib/libalpm/add.c | 1 - lib/libalpm/alpm.h | 16 +++++++++------- lib/libalpm/be_local.c | 9 ++++----- lib/libalpm/db.h | 2 -- lib/libalpm/dload.h | 2 -- lib/libalpm/package.c | 10 +++++----- lib/libalpm/package.h | 9 ++++----- lib/libalpm/util.c | 12 ++++++------ lib/libalpm/util.h | 3 +-- 9 files changed, 29 insertions(+), 35 deletions(-) (limited to 'lib') diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index 653d2bd9..9fb3b14d 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -22,7 +22,6 @@ #include #include -#include #include #include #include diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index a93d4e3e..9fda9406 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -27,9 +27,9 @@ extern "C" { #endif -#include /* for off_t */ -#include /* for time_t */ -#include /* for va_list */ +#include /* int64_t */ +#include /* off_t */ +#include /* va_list */ #include @@ -44,6 +44,8 @@ extern "C" { * @{ */ +typedef int64_t alpm_time_t; + /* * Enumerations * These ones are used in multiple contexts, so are forward-declared. @@ -222,8 +224,8 @@ typedef struct _alpm_pgpkey_t { char *uid; char *name; char *email; - time_t created; - time_t expires; + alpm_time_t created; + alpm_time_t expires; } alpm_pgpkey_t; /** Signature result. Contains the key, status, and validity of a given @@ -754,13 +756,13 @@ const char *alpm_pkg_get_url(alpm_pkg_t *pkg); * @param pkg a pointer to package * @return the timestamp of the build time */ -time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg); +alpm_time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg); /** Returns the install timestamp of the package. * @param pkg a pointer to package * @return the timestamp of the install time */ -time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg); +alpm_time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg); /** Returns the packager's name. * @param pkg a pointer to package diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 56cf38bb..21d27481 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -28,7 +28,6 @@ #include /* intmax_t */ #include #include -#include #include /* PATH_MAX */ /* libalpm */ @@ -69,13 +68,13 @@ static const char *_cache_get_url(alpm_pkg_t *pkg) return pkg->url; } -static time_t _cache_get_builddate(alpm_pkg_t *pkg) +static alpm_time_t _cache_get_builddate(alpm_pkg_t *pkg) { LAZY_LOAD(INFRQ_DESC, 0); return pkg->builddate; } -static time_t _cache_get_installdate(alpm_pkg_t *pkg) +static alpm_time_t _cache_get_installdate(alpm_pkg_t *pkg) { LAZY_LOAD(INFRQ_DESC, 0); return pkg->installdate; @@ -794,11 +793,11 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq } if(info->builddate) { fprintf(fp, "%%BUILDDATE%%\n" - "%ld\n\n", info->builddate); + "%jd\n\n", (intmax_t)info->builddate); } if(info->installdate) { fprintf(fp, "%%INSTALLDATE%%\n" - "%ld\n\n", info->installdate); + "%jd\n\n", (intmax_t)info->installdate); } if(info->packager) { fprintf(fp, "%%PACKAGER%%\n" diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index 224bfbeb..a1249d3e 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -22,8 +22,6 @@ #ifndef _ALPM_DB_H #define _ALPM_DB_H -#include - /* libarchive */ #include #include diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h index 5442c0e2..57a69f93 100644 --- a/lib/libalpm/dload.h +++ b/lib/libalpm/dload.h @@ -23,8 +23,6 @@ #include "alpm_list.h" #include "alpm.h" -#include - struct dload_payload { alpm_handle_t *handle; const char *tempfile_openmode; diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index a5ff238f..0b0bf6e4 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -87,12 +87,12 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg) * populated package structures. */ static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; } static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; } -static time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; } -static time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; } +static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; } +static alpm_time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; } static const char *_pkg_get_packager(alpm_pkg_t *pkg) { return pkg->packager; } static const char *_pkg_get_arch(alpm_pkg_t *pkg) { return pkg->arch; } static off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; } -static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; } +static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; } static int _pkg_has_scriptlet(alpm_pkg_t *pkg) { return pkg->scriptlet; } static alpm_list_t *_pkg_get_licenses(alpm_pkg_t *pkg) { return pkg->licenses; } @@ -200,14 +200,14 @@ const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg) return pkg->ops->get_url(pkg); } -time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg) +alpm_time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); pkg->handle->pm_errno = 0; return pkg->ops->get_builddate(pkg); } -time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg) +alpm_time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return -1); pkg->handle->pm_errno = 0; diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index eff7d898..82a83264 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -27,7 +27,6 @@ #include "config.h" /* ensure off_t is correct length */ #include /* off_t */ -#include /* time_t */ #include "alpm.h" #include "backup.h" @@ -44,8 +43,8 @@ struct pkg_operations { const char *(*get_desc) (alpm_pkg_t *); const char *(*get_url) (alpm_pkg_t *); - time_t (*get_builddate) (alpm_pkg_t *); - time_t (*get_installdate) (alpm_pkg_t *); + alpm_time_t (*get_builddate) (alpm_pkg_t *); + alpm_time_t (*get_installdate) (alpm_pkg_t *); const char *(*get_packager) (alpm_pkg_t *); const char *(*get_arch) (alpm_pkg_t *); off_t (*get_isize) (alpm_pkg_t *); @@ -89,8 +88,8 @@ struct __alpm_pkg_t { char *base64_sig; char *arch; - time_t builddate; - time_t installdate; + alpm_time_t builddate; + alpm_time_t installdate; off_t size; off_t isize; diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 243978cd..d723aee2 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1107,7 +1107,7 @@ off_t _alpm_strtoofft(const char *line) return (off_t)result; } -time_t _alpm_parsedate(const char *line) +alpm_time_t _alpm_parsedate(const char *line) { char *end; long long result; @@ -1120,24 +1120,24 @@ time_t _alpm_parsedate(const char *line) setlocale(LC_TIME, "C"); strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm); setlocale(LC_TIME, ""); - return mktime(&tmp_tm); + return (alpm_time_t)mktime(&tmp_tm); } result = strtoll(line, &end, 10); if (result == 0 && end == line) { /* line was not a number */ errno = EINVAL; - return (time_t)0; + return 0; } else if (errno == ERANGE) { /* line does not fit in long long */ - return (time_t)0; + return 0; } else if (*end) { /* line began with a number but has junk left over at the end */ errno = EINVAL; - return (time_t)0; + return 0; } - return (time_t)result; + return (alpm_time_t)result; } /** diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 2a2d3a93..017bf518 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -35,7 +35,6 @@ #include #include #include /* size_t */ -#include #include /* struct stat */ #include /* struct archive */ #include /* fabs */ @@ -120,7 +119,7 @@ int _alpm_splitname(const char *target, char **name, char **version, unsigned long *name_hash); unsigned long _alpm_hash_sdbm(const char *str); off_t _alpm_strtoofft(const char *line); -time_t _alpm_parsedate(const char *line); +alpm_time_t _alpm_parsedate(const char *line); int _alpm_raw_cmp(const char *first, const char *second); int _alpm_raw_ncmp(const char *first, const char *second, size_t max); int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode); -- cgit v1.2.3-24-g4f1b