Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-03-25 21:23:14 -0500
committerDan McGee <dan@archlinux.org>2008-03-27 12:07:26 -0500
commitf8c737d3b6b28373a69d5979a4ba2e31b77baa62 (patch)
treeda339690b576917897b80a0d305c695d17535237 /lib/libalpm/util.c
parent1dfd841e40344ff401e0d9e8d61b55cb64b2681f (diff)
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>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 806f601c..7de5b069 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -673,4 +673,33 @@ int _alpm_test_md5sum(const char *filepath, const char *md5sum)
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: */