index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Dan McGee <dan@archlinux.org> | 2011-01-07 20:35:43 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-01-07 20:55:05 -0600 |
commit | 4bc6ed56aa48784c8caf56c3a6fb1a3c972d221c (patch) | |
tree | 164ca843d1450f9b3534760fb670adc39cfe8e08 | |
parent | d288240426551e9d58a708e28fe0217e56d017d6 (diff) |
-rw-r--r-- | lib/libalpm/be_local.c | 25 | ||||
-rw-r--r-- | lib/libalpm/be_package.c | 12 | ||||
-rw-r--r-- | lib/libalpm/be_sync.c | 13 | ||||
-rw-r--r-- | lib/libalpm/util.c | 13 | ||||
-rw-r--r-- | lib/libalpm/util.h | 1 |
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 4c8e0e9c..109edf49 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -28,7 +28,6 @@ #include <stdint.h> /* intmax_t */ #include <sys/stat.h> #include <dirent.h> -#include <ctype.h> #include <time.h> #include <limits.h> /* PATH_MAX */ #include <locale.h> /* setlocale */ @@ -570,33 +569,13 @@ int _alpm_local_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) goto error; } _alpm_strtrim(line); - - char first = tolower((unsigned char)line[0]); - if(first > 'a' && first < 'z') { - struct tm tmp_tm = {0}; /* initialize to null in case of failure */ - setlocale(LC_TIME, "C"); - strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm); - info->builddate = mktime(&tmp_tm); - setlocale(LC_TIME, ""); - } else { - info->builddate = atol(line); - } + info->builddate = _alpm_parsedate(line); } else if(strcmp(line, "%INSTALLDATE%") == 0) { if(fgets(line, sizeof(line), fp) == NULL) { goto error; } _alpm_strtrim(line); - - char first = tolower((unsigned char)line[0]); - if(first > 'a' && first < 'z') { - struct tm tmp_tm = {0}; /* initialize to null in case of failure */ - setlocale(LC_TIME, "C"); - strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm); - info->installdate = mktime(&tmp_tm); - setlocale(LC_TIME, ""); - } else { - info->installdate = atol(line); - } + info->installdate = _alpm_parsedate(line); } else if(strcmp(line, "%PACKAGER%") == 0) { if(fgets(line, sizeof(line), fp) == NULL) { goto error; diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c index ae9b9533..4ea3eba8 100644 --- a/lib/libalpm/be_package.c +++ b/lib/libalpm/be_package.c @@ -24,7 +24,6 @@ #include <stdlib.h> #include <string.h> #include <limits.h> -#include <ctype.h> #include <locale.h> /* setlocale */ #include <errno.h> @@ -203,16 +202,7 @@ static int parse_descfile(struct archive *a, pmpkg_t *newpkg) } else if(strcmp(key, "license") == 0) { newpkg->licenses = alpm_list_add(newpkg->licenses, strdup(ptr)); } else if(strcmp(key, "builddate") == 0) { - char first = tolower((unsigned char)ptr[0]); - if(first > 'a' && first < 'z') { - struct tm tmp_tm = {0}; /* initialize to null in case of failure */ - setlocale(LC_TIME, "C"); - strptime(ptr, "%a %b %e %H:%M:%S %Y", &tmp_tm); - newpkg->builddate = mktime(&tmp_tm); - setlocale(LC_TIME, ""); - } else { - newpkg->builddate = atol(ptr); - } + newpkg->builddate = _alpm_parsedate(ptr); } else if(strcmp(key, "packager") == 0) { STRDUP(newpkg->packager, ptr, RET_ERR(PM_ERR_MEMORY, -1)); } else if(strcmp(key, "arch") == 0) { diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index c7d8e045..81f3e46e 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -21,7 +21,6 @@ #include "config.h" #include <errno.h> -#include <ctype.h> #include <locale.h> #include <limits.h> @@ -313,17 +312,7 @@ static int sync_db_read(pmdb_t *db, struct archive *archive, struct archive_entr READ_AND_STORE(pkg->arch); } else if(strcmp(line, "%BUILDDATE%") == 0) { READ_NEXT(line); - char first = tolower((unsigned char)line[0]); - if(first > 'a' && first < 'z') { - /* initialize to null in case of failure */ - struct tm tmp_tm = {0}; - setlocale(LC_TIME, "C"); - strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm); - pkg->builddate = mktime(&tmp_tm); - setlocale(LC_TIME, ""); - } else { - pkg->builddate = atol(line); - } + pkg->builddate = _alpm_parsedate(line); } else if(strcmp(line, "%PACKAGER%") == 0) { READ_AND_STORE(pkg->packager); } else if(strcmp(line, "%CSIZE%") == 0) { diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 18245646..5f7512fb 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -923,4 +923,17 @@ unsigned long _alpm_hash_sdbm(const char *str) return(hash); } +long _alpm_parsedate(const char *line) +{ + if(isalpha((unsigned char)line[0])) { + /* initialize to null in case of failure */ + struct tm tmp_tm = { 0 }; + setlocale(LC_TIME, "C"); + strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm); + setlocale(LC_TIME, ""); + return(mktime(&tmp_tm)); + } + return(atol(line)); +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 10f367fd..be5c1d9b 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -95,6 +95,7 @@ int _alpm_test_md5sum(const char *filepath, const char *md5sum); int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b); int _alpm_splitname(const char *target, pmpkg_t *pkg); unsigned long _alpm_hash_sdbm(const char *str); +long _alpm_parsedate(const char *line); #ifndef HAVE_STRSEP char *strsep(char **, const char *); |