index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | lib/libalpm/util.c | 59 |
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index e1413a25..9d86331b 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -43,7 +43,6 @@ /* libalpm */ #include "util.h" #include "log.h" -#include "error.h" #include "package.h" #include "alpm.h" #include "alpm_list.h" @@ -382,7 +381,7 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn) ALPM_LOG_FUNC; if((_archive = archive_read_new()) == NULL) - RET_ERR(PM_ERR_LIBARCHIVE_ERROR, -1); + RET_ERR(PM_ERR_LIBARCHIVE, -1); archive_read_support_compression_all(_archive); archive_read_support_format_all(_archive); @@ -640,13 +639,7 @@ char SYMEXPORT *alpm_get_md5sum(const char *filename) ret = md5_file(filename, output); if (ret > 0) { - if (ret == 1) { - _alpm_log(PM_LOG_ERROR, _("md5: %s can't be opened\n"), filename); - } else if (ret == 2) { - _alpm_log(PM_LOG_ERROR, _("md5: %s can't be read\n"), filename); - } - - return(NULL); + RET_ERR(PM_ERR_NOT_A_FILE, NULL); } /* Convert the result to something readable */ @@ -660,4 +653,52 @@ char SYMEXPORT *alpm_get_md5sum(const char *filename) return(md5sum); } +int _alpm_test_md5sum(const char *filepath, const char *md5sum) +{ + char *md5sum2; + int ret; + + md5sum2 = alpm_get_md5sum(filepath); + + if(md5sum == NULL || md5sum2 == NULL) { + ret = -1; + } else if(strcmp(md5sum, md5sum2) != 0) { + ret = 1; + } else { + ret = 0; + } + + FREE(md5sum2); + return(ret); +} + +char *_alpm_archive_fgets(char *line, size_t size, struct archive *a) +{ + /* for now, just read one char at a time until we get to a + * '\n' char. we can optimize this later with an internal + * buffer. */ + /* leave room for zero terminator */ + char *last = line + size - 1; + char *i; + + for(i = line; i < last; i++) { + int ret = archive_read_data(a, i, 1); + /* special check for first read- if null, return null, + * this indicates EOF */ + if(i == line && (ret <= 0 || *i == '\0')) { + return(NULL); + } + /* check if read value was null or newline */ + if(ret <= 0 || *i == '\0' || *i == '\n') { + last = i + 1; + break; + } + } + + /* always null terminate the buffer */ + *last = '\0'; + + return(line); +} + /* vim: set ts=2 sw=2 noet: */ |