mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
Add an archive_fgets() function
This crude function allows reading from an archive on a line-by-line basis similar to the familiar fgets() call on a FILE stream. This is the first step in being able to read DB entries straight from an archive. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
1dfd841e40
commit
f8c737d3b6
@ -673,4 +673,33 @@ int _alpm_test_md5sum(const char *filepath, const char *md5sum)
|
|||||||
return(ret);
|
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: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/stat.h> /* struct stat */
|
#include <sys/stat.h> /* struct stat */
|
||||||
|
#include <archive.h> /* struct archive */
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
#include <libintl.h> /* here so it doesn't need to be included elsewhere */
|
#include <libintl.h> /* here so it doesn't need to be included elsewhere */
|
||||||
@ -66,6 +67,7 @@ char *_alpm_filecache_find(const char *filename);
|
|||||||
const char *_alpm_filecache_setup(void);
|
const char *_alpm_filecache_setup(void);
|
||||||
int _alpm_lstat(const char *path, struct stat *buf);
|
int _alpm_lstat(const char *path, struct stat *buf);
|
||||||
int _alpm_test_md5sum(const char *filepath, const char *md5sum);
|
int _alpm_test_md5sum(const char *filepath, const char *md5sum);
|
||||||
|
char *_alpm_archive_fgets(char *line, size_t size, struct archive *a);
|
||||||
|
|
||||||
#ifndef HAVE_STRVERSCMP
|
#ifndef HAVE_STRVERSCMP
|
||||||
int strverscmp(const char *, const char *);
|
int strverscmp(const char *, const char *);
|
||||||
|
Loading…
Reference in New Issue
Block a user