diff options
author | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-11-10 01:07:09 (EST) |
---|---|---|
committer | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-11-10 01:07:09 (EST) |
commit | 90788433e3cfb11817839cd52ef9d75c2a504468 (patch) | |
tree | cb41eb482467387cd5cd289d7a43d44b2c2a13d2 /libopkg | |
parent | dc23bec5af327cff093dc471441124944c39cc9c (diff) |
Cleanup trim_alloc().
git-svn-id: http://opkg.googlecode.com/svn/trunk@278 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
Diffstat (limited to 'libopkg')
-rw-r--r-- | libopkg/opkg_utils.c | 27 | ||||
-rw-r--r-- | libopkg/opkg_utils.h | 2 |
2 files changed, 10 insertions, 19 deletions
diff --git a/libopkg/opkg_utils.c b/libopkg/opkg_utils.c index 20af4d5..e293197 100644 --- a/libopkg/opkg_utils.c +++ b/libopkg/opkg_utils.c @@ -100,36 +100,27 @@ char **read_raw_pkgs_from_stream(FILE *fp) } /* something to remove whitespace, a hash pooper */ -char *trim_alloc(char *line) +char *trim_alloc(const char *src) { - char *new; - char *dest, *src, *end; - - new = xcalloc(1, strlen(line) + 1); - dest = new, src = line, end = line + (strlen(line) - 1); + const char *end; /* remove it from the front */ while(src && isspace(*src) && *src) src++; + + end = src + (strlen(src) - 1); + /* and now from the back */ while((end > src) && isspace(*end)) end--; + end++; - *end = '\0'; - strcpy(new, src); - /* this does from the first space - * blasting away any versions stuff in depends - while(src && - !isspace(*src) && - *src) - *dest++ = *src++; - *dest = '\0'; - */ - - return new; + + /* xstrndup will NULL terminate for us */ + return xstrndup(src, end-src); } int line_is_blank(const char *line) diff --git a/libopkg/opkg_utils.h b/libopkg/opkg_utils.h index a6c9eb0..fdba37d 100644 --- a/libopkg/opkg_utils.h +++ b/libopkg/opkg_utils.h @@ -28,7 +28,7 @@ void print_error_list(void); long unsigned int get_available_blocks(char * filesystem); char **read_raw_pkgs_from_file(const char *file_name); char **read_raw_pkgs_from_stream(FILE *fp); -char *trim_alloc(char * line); +char *trim_alloc(const char *line); int line_is_blank(const char *line); #endif |