From f547c5906e484a05abb12b2a3f5d704c3cf7b60f Mon Sep 17 00:00:00 2001 From: graham.gower Date: Tue, 10 Nov 2009 22:18:23 -0500 Subject: Cleanup parsing of packages. This diff is loosely based on a patch by Jo-Philipp Wich posted in the bugtracker (Issue #24). Peak memory consumption while parsing package lists is dramatically reduced. Thanks to Camille Moncelier for fixing problems after reallocing for long lines. git-svn-id: http://opkg.googlecode.com/svn/trunk@283 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- (limited to 'libopkg/opkg_utils.c') diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c index e293197..d40999f 100644 --- a/libopkg/opkg_utils.c +++ b/libopkg/opkg_utils.c @@ -47,58 +47,6 @@ long unsigned int get_available_blocks(char * filesystem) return 0; } -char **read_raw_pkgs_from_file(const char *file_name) -{ - FILE *fp; - char **ret; - - if(!(fp = fopen(file_name, "r"))){ - fprintf(stderr, "can't get %s open for read\n", file_name); - return NULL; - } - - ret = read_raw_pkgs_from_stream(fp); - - fclose(fp); - - return ret; -} - -char **read_raw_pkgs_from_stream(FILE *fp) -{ - char **raw = NULL, *buf, *scout; - int count = 0; - size_t size = 512; - - buf = xcalloc(1, size); - - while (fgets(buf, size, fp)) { - while (strlen (buf) == (size - 1) - && buf[size-2] != '\n') { - size_t o = size - 1; - size *= 2; - buf = xrealloc (buf, size); - if (fgets (buf + o, size - o, fp) == NULL) - break; - } - - if(!(count % 50)) - raw = xrealloc(raw, (count + 50) * sizeof(char *)); - - if((scout = strchr(buf, '\n'))) - *scout = '\0'; - - raw[count++] = xstrdup(buf); - } - - raw = xrealloc(raw, (count + 1) * sizeof(char *)); - raw[count] = NULL; - - free (buf); - - return raw; -} - /* something to remove whitespace, a hash pooper */ char *trim_alloc(const char *src) { -- cgit v0.9.1