1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

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 <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-09-07 10:21:47 -05:00
parent 759f435fb9
commit 5f3629bea0
12 changed files with 34 additions and 38 deletions

View File

@ -22,7 +22,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <fcntl.h> #include <fcntl.h>

View File

@ -27,9 +27,9 @@
extern "C" { extern "C" {
#endif #endif
#include <sys/types.h> /* for off_t */ #include <inttypes.h> /* int64_t */
#include <time.h> /* for time_t */ #include <sys/types.h> /* off_t */
#include <stdarg.h> /* for va_list */ #include <stdarg.h> /* va_list */
#include <alpm_list.h> #include <alpm_list.h>
@ -44,6 +44,8 @@ extern "C" {
* @{ * @{
*/ */
typedef int64_t alpm_time_t;
/* /*
* Enumerations * Enumerations
* These ones are used in multiple contexts, so are forward-declared. * These ones are used in multiple contexts, so are forward-declared.
@ -222,8 +224,8 @@ typedef struct _alpm_pgpkey_t {
char *uid; char *uid;
char *name; char *name;
char *email; char *email;
time_t created; alpm_time_t created;
time_t expires; alpm_time_t expires;
} alpm_pgpkey_t; } alpm_pgpkey_t;
/** Signature result. Contains the key, status, and validity of a given /** 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 * @param pkg a pointer to package
* @return the timestamp of the build time * @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. /** Returns the install timestamp of the package.
* @param pkg a pointer to package * @param pkg a pointer to package
* @return the timestamp of the install time * @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. /** Returns the packager's name.
* @param pkg a pointer to package * @param pkg a pointer to package

View File

@ -28,7 +28,6 @@
#include <stdint.h> /* intmax_t */ #include <stdint.h> /* intmax_t */
#include <sys/stat.h> #include <sys/stat.h>
#include <dirent.h> #include <dirent.h>
#include <time.h>
#include <limits.h> /* PATH_MAX */ #include <limits.h> /* PATH_MAX */
/* libalpm */ /* libalpm */
@ -69,13 +68,13 @@ static const char *_cache_get_url(alpm_pkg_t *pkg)
return pkg->url; 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); LAZY_LOAD(INFRQ_DESC, 0);
return pkg->builddate; 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); LAZY_LOAD(INFRQ_DESC, 0);
return pkg->installdate; 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) { if(info->builddate) {
fprintf(fp, "%%BUILDDATE%%\n" fprintf(fp, "%%BUILDDATE%%\n"
"%ld\n\n", info->builddate); "%jd\n\n", (intmax_t)info->builddate);
} }
if(info->installdate) { if(info->installdate) {
fprintf(fp, "%%INSTALLDATE%%\n" fprintf(fp, "%%INSTALLDATE%%\n"
"%ld\n\n", info->installdate); "%jd\n\n", (intmax_t)info->installdate);
} }
if(info->packager) { if(info->packager) {
fprintf(fp, "%%PACKAGER%%\n" fprintf(fp, "%%PACKAGER%%\n"

View File

@ -22,8 +22,6 @@
#ifndef _ALPM_DB_H #ifndef _ALPM_DB_H
#define _ALPM_DB_H #define _ALPM_DB_H
#include <time.h>
/* libarchive */ /* libarchive */
#include <archive.h> #include <archive.h>
#include <archive_entry.h> #include <archive_entry.h>

View File

@ -23,8 +23,6 @@
#include "alpm_list.h" #include "alpm_list.h"
#include "alpm.h" #include "alpm.h"
#include <time.h>
struct dload_payload { struct dload_payload {
alpm_handle_t *handle; alpm_handle_t *handle;
const char *tempfile_openmode; const char *tempfile_openmode;

View File

@ -87,8 +87,8 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
* populated package structures. */ * populated package structures. */
static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; } 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 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 alpm_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_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_packager(alpm_pkg_t *pkg) { return pkg->packager; }
static const char *_pkg_get_arch(alpm_pkg_t *pkg) { return pkg->arch; } 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 off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; }
@ -200,14 +200,14 @@ const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg)
return pkg->ops->get_url(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); ASSERT(pkg != NULL, return -1);
pkg->handle->pm_errno = 0; pkg->handle->pm_errno = 0;
return pkg->ops->get_builddate(pkg); 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); ASSERT(pkg != NULL, return -1);
pkg->handle->pm_errno = 0; pkg->handle->pm_errno = 0;

View File

@ -27,7 +27,6 @@
#include "config.h" /* ensure off_t is correct length */ #include "config.h" /* ensure off_t is correct length */
#include <sys/types.h> /* off_t */ #include <sys/types.h> /* off_t */
#include <time.h> /* time_t */
#include "alpm.h" #include "alpm.h"
#include "backup.h" #include "backup.h"
@ -44,8 +43,8 @@
struct pkg_operations { struct pkg_operations {
const char *(*get_desc) (alpm_pkg_t *); const char *(*get_desc) (alpm_pkg_t *);
const char *(*get_url) (alpm_pkg_t *); const char *(*get_url) (alpm_pkg_t *);
time_t (*get_builddate) (alpm_pkg_t *); alpm_time_t (*get_builddate) (alpm_pkg_t *);
time_t (*get_installdate) (alpm_pkg_t *); alpm_time_t (*get_installdate) (alpm_pkg_t *);
const char *(*get_packager) (alpm_pkg_t *); const char *(*get_packager) (alpm_pkg_t *);
const char *(*get_arch) (alpm_pkg_t *); const char *(*get_arch) (alpm_pkg_t *);
off_t (*get_isize) (alpm_pkg_t *); off_t (*get_isize) (alpm_pkg_t *);
@ -89,8 +88,8 @@ struct __alpm_pkg_t {
char *base64_sig; char *base64_sig;
char *arch; char *arch;
time_t builddate; alpm_time_t builddate;
time_t installdate; alpm_time_t installdate;
off_t size; off_t size;
off_t isize; off_t isize;

View File

@ -1107,7 +1107,7 @@ off_t _alpm_strtoofft(const char *line)
return (off_t)result; return (off_t)result;
} }
time_t _alpm_parsedate(const char *line) alpm_time_t _alpm_parsedate(const char *line)
{ {
char *end; char *end;
long long result; long long result;
@ -1120,24 +1120,24 @@ time_t _alpm_parsedate(const char *line)
setlocale(LC_TIME, "C"); setlocale(LC_TIME, "C");
strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm); strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm);
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
return mktime(&tmp_tm); return (alpm_time_t)mktime(&tmp_tm);
} }
result = strtoll(line, &end, 10); result = strtoll(line, &end, 10);
if (result == 0 && end == line) { if (result == 0 && end == line) {
/* line was not a number */ /* line was not a number */
errno = EINVAL; errno = EINVAL;
return (time_t)0; return 0;
} else if (errno == ERANGE) { } else if (errno == ERANGE) {
/* line does not fit in long long */ /* line does not fit in long long */
return (time_t)0; return 0;
} else if (*end) { } else if (*end) {
/* line began with a number but has junk left over at the end */ /* line began with a number but has junk left over at the end */
errno = EINVAL; errno = EINVAL;
return (time_t)0; return 0;
} }
return (time_t)result; return (alpm_time_t)result;
} }
/** /**

View File

@ -35,7 +35,6 @@
#include <string.h> #include <string.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> /* size_t */ #include <stddef.h> /* size_t */
#include <time.h>
#include <sys/stat.h> /* struct stat */ #include <sys/stat.h> /* struct stat */
#include <archive.h> /* struct archive */ #include <archive.h> /* struct archive */
#include <math.h> /* fabs */ #include <math.h> /* fabs */
@ -120,7 +119,7 @@ int _alpm_splitname(const char *target, char **name, char **version,
unsigned long *name_hash); unsigned long *name_hash);
unsigned long _alpm_hash_sdbm(const char *str); unsigned long _alpm_hash_sdbm(const char *str);
off_t _alpm_strtoofft(const char *line); 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_cmp(const char *first, const char *second);
int _alpm_raw_ncmp(const char *first, const char *second, size_t max); 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); int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode);

View File

@ -25,6 +25,7 @@
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> /* off_t */ #include <sys/types.h> /* off_t */
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <wchar.h> #include <wchar.h>
#include <limits.h> /* UINT_MAX */ #include <limits.h> /* UINT_MAX */

View File

@ -26,6 +26,7 @@
#include <unistd.h> #include <unistd.h>
#include <limits.h> #include <limits.h>
#include <errno.h> #include <errno.h>
#include <time.h>
#include <alpm.h> #include <alpm.h>
#include <alpm_list.h> #include <alpm_list.h>
@ -74,11 +75,11 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
from = alpm_pkg_get_origin(pkg); from = alpm_pkg_get_origin(pkg);
/* set variables here, do all output below */ /* set variables here, do all output below */
bdate = alpm_pkg_get_builddate(pkg); bdate = (time_t)alpm_pkg_get_builddate(pkg);
if(bdate) { if(bdate) {
strftime(bdatestr, 50, "%c", localtime(&bdate)); strftime(bdatestr, 50, "%c", localtime(&bdate));
} }
idate = alpm_pkg_get_installdate(pkg); idate = (time_t)alpm_pkg_get_installdate(pkg);
if(idate) { if(idate) {
strftime(idatestr, 50, "%c", localtime(&idate)); strftime(idatestr, 50, "%c", localtime(&idate));
} }

View File

@ -23,7 +23,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <time.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>