aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2024-01-31 21:39:24 +0100
committerFabian Groffen <grobian@gentoo.org>2024-01-31 21:39:24 +0100
commit17e518250d3cabfec9ecc417275a42858b590297 (patch)
tree71118eceb04e73d0a9876b9f5ef3ba3b94083388
parentlibq/hash.h: update copyright for previous commit (diff)
downloadportage-utils-17e518250d3cabfec9ecc417275a42858b590297.tar.gz
portage-utils-17e518250d3cabfec9ecc417275a42858b590297.tar.bz2
portage-utils-17e518250d3cabfec9ecc417275a42858b590297.zip
libq/contents: add variant specifying buffer length
This seems necessary for PR #21, but keep the original code structure largely in-tact. Signed-off-by: Fabian Groffen <grobian@gentoo.org>
-rw-r--r--libq/contents.c53
-rw-r--r--libq/contents.h5
2 files changed, 38 insertions, 20 deletions
diff --git a/libq/contents.c b/libq/contents.c
index 7f4351d..feb1c0b 100644
--- a/libq/contents.c
+++ b/libq/contents.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2020 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*
* Copyright 2005-2008 Ned Ludd - <solar@gentoo.org>
@@ -19,18 +19,20 @@
* Parse a line of CONTENTS file and provide access to the individual fields
*/
contents_entry *
-contents_parse_line(char *line)
+contents_parse_line_len(char *line, size_t len)
{
static contents_entry e;
char *p;
- if (line == NULL || *line == '\0' || *line == '\n')
+ if (len == 0 || line == NULL || *line == '\0' || *line == '\n')
return NULL;
/* chop trailing newline */
- p = &line[strlen(line) - 1];
- if (*p == '\n')
+ p = &line[len - 1];
+ if (*p == '\n') {
*p = '\0';
+ len--;
+ }
memset(&e, 0x00, sizeof(e));
e._data = line;
@@ -53,23 +55,38 @@ contents_parse_line(char *line)
/* obj /bin/bash 62ed51c8b23866777552643ec57614b0 1120707577 */
case CONTENTS_OBJ:
- if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
- return NULL;
- *e.mtime_str++ = '\0';
- if ((e.digest = strrchr(e.name, ' ')) == NULL)
- return NULL;
- *e.digest++ = '\0';
+ for (p = &e.name[len - 1]; p >= e.name; p--) {
+ if (*p == ' ') {
+ if (e.mtime_str == NULL)
+ e.mtime_str = p + 1;
+ else if (e.digest == NULL)
+ e.digest = p + 1;
+ *p = '\0';
+
+ if (e.digest != NULL)
+ break;
+ }
+ }
break;
/* sym /bin/sh -> bash 1120707577 */
case CONTENTS_SYM:
- if ((e.mtime_str = strrchr(e.name, ' ')) == NULL)
- return NULL;
- *e.mtime_str++ = '\0';
- if ((e.sym_target = strstr(e.name, " -> ")) == NULL)
- return NULL;
- *e.sym_target = '\0';
- e.sym_target += 4;
+ for (p = &e.name[len - 1]; p >= e.name; p--) {
+ if (*p == ' ') {
+ if (e.mtime_str == NULL) {
+ e.mtime_str = p + 1;
+ } else if (e.sym_target == NULL) {
+ if (strncmp(p, " -> ", sizeof(" -> ") - 1) == 0)
+ e.sym_target = p + sizeof(" -> ") - 1;
+ else
+ continue;
+ }
+ *p = '\0';
+
+ if (e.sym_target != NULL)
+ break;
+ }
+ }
break;
}
diff --git a/libq/contents.h b/libq/contents.h
index c766827..a0a5a63 100644
--- a/libq/contents.h
+++ b/libq/contents.h
@@ -1,5 +1,5 @@
/*
- * Copyright 2005-2019 Gentoo Foundation
+ * Copyright 2005-2024 Gentoo Foundation
* Distributed under the terms of the GNU General Public License v2
*
* Copyright 2005-2008 Ned Ludd - <solar@gentoo.org>
@@ -24,6 +24,7 @@ typedef struct {
long mtime;
} contents_entry;
-contents_entry *contents_parse_line(char *line);
+contents_entry *contents_parse_line_len(char *line, size_t len);
+#define contents_parse_line(L) contents_parse_line_len(L, strlen(L))
#endif