diff options
author | Dan McGee <dan@archlinux.org> | 2008-05-11 16:49:01 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2010-10-13 23:53:18 +1000 |
commit | b9a531c2d7e3eefab5d987d83a1cb869e1220fac (patch) | |
tree | a1226658c13598041728d8072169e23ebb60b15d /lib/libalpm/be_files.c | |
parent | 6cebd4e6028f717663cda0af1221f3ac74d5ab9f (diff) | |
download | pacman-b9a531c2d7e3eefab5d987d83a1cb869e1220fac.tar.xz |
Move changelog functions to callback struct
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_files.c')
-rw-r--r-- | lib/libalpm/be_files.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index e8573947..737f22c8 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -230,6 +230,63 @@ alpm_list_t *_cache_get_backup(pmpkg_t *pkg) return pkg->backup; } +/** + * Open a package changelog for reading. Similar to fopen in functionality, + * except that the returned 'file stream' is from the database. + * @param pkg the package (from db) to read the changelog + * @return a 'file stream' to the package changelog + */ +void *_cache_changelog_open(pmpkg_t *pkg) +{ + ALPM_LOG_FUNC; + + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + char clfile[PATH_MAX]; + snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog", + alpm_option_get_dbpath(), + alpm_db_get_name(alpm_pkg_get_db(pkg)), + alpm_pkg_get_name(pkg), + alpm_pkg_get_version(pkg)); + return fopen(clfile, "r"); +} + +/** + * Read data from an open changelog 'file stream'. Similar to fread in + * functionality, this function takes a buffer and amount of data to read. + * @param ptr a buffer to fill with raw changelog data + * @param size the size of the buffer + * @param pkg the package that the changelog is being read from + * @param fp a 'file stream' to the package changelog + * @return the number of characters read, or 0 if there is no more data + */ +size_t _cache_changelog_read(void *ptr, size_t size, + const pmpkg_t *pkg, const void *fp) +{ + return ( fread(ptr, 1, size, (FILE*)fp) ); +} + +/* +int _cache_changelog_feof(const pmpkg_t *pkg, void *fp) +{ + return( feof((FILE*)fp) ); +} +*/ + +/** + * Close a package changelog for reading. Similar to fclose in functionality, + * except that the 'file stream' is from the database. + * @param pkg the package that the changelog was read from + * @param fp a 'file stream' to the package changelog + * @return whether closing the package changelog stream was successful + */ +int _cache_changelog_close(const pmpkg_t *pkg, void *fp) +{ + return( fclose((FILE*)fp) ); +} + /** The sync database operations struct. Get package fields through * lazy accessor methods that handle any backend loading and caching * logic. @@ -290,6 +347,10 @@ static struct pkg_operations local_pkg_ops = { .get_deltas = _cache_get_deltas, .get_files = _cache_get_files, .get_backup = _cache_get_backup, + + .changelog_open = _cache_changelog_open, + .changelog_read = _cache_changelog_read, + .changelog_close = _cache_changelog_close, }; static int checkdbdir(pmdb_t *db) |