summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dirent.c41
1 files changed, 29 insertions, 12 deletions
diff --git a/src/dirent.c b/src/dirent.c
index 7783120..eb92a2b 100644
--- a/src/dirent.c
+++ b/src/dirent.c
@@ -30,13 +30,19 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char **name_buf,
size_t len;
char **buf;
- len = strlen(dirent->name) + 1;
+ len = strlen(dirent->name);
if (*name_len + len <= *name_buf_len) {
- *name_buf_len -= len;
buf = name_buf;
+ if (**buf != '\0') {
+ ++len;
+ }
+ *name_buf_len -= len;
} else if (*pref_len + len <= *pref_buf_len) {
- *pref_buf_len -= len;
buf = pref_buf;
+ if (**buf != '\0') {
+ ++len;
+ }
+ *pref_buf_len -= len;
} else {
return OPKG_OPK_ERROR;
}
@@ -48,10 +54,13 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char **name_buf,
return OPKG_OPK_ERROR;
}
- **buf = '/';
- *buf += 1;
- memcpy(*buf, dirent->name, len - 1);
- *buf += len - 1;
+ if (**buf != '\0') {
+ **buf = '/';
+ *buf += 1;
+ --len;
+ }
+ memcpy(*buf, dirent->name, len);
+ *buf += len;
return OPKG_OPK_OK;
}
@@ -63,6 +72,8 @@ opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char *name_buf,
size_t name_len = 0;
size_t pref_len = 0;
+ name_buf[0] = '\0';
+ pref_buf[0] = '\0';
if (_opkg_opk_dirent_name_prefix(dirent, &name_buf, &name_buf_len,
&pref_buf, &pref_buf_len, &name_len, &pref_len)
== OPKG_OPK_ERROR) {
@@ -80,7 +91,10 @@ _opkg_opk_dirent_full_name(struct opkg_opk_dirent *dirent, char **cur,
size_t len;
char *buf;
- len = strlen(dirent->name) + 1;
+ len = strlen(dirent->name);
+ if (dirent->parent != NULL) {
+ ++len;
+ }
*buf_len += len;
if (dirent->parent == NULL) {
@@ -94,10 +108,13 @@ _opkg_opk_dirent_full_name(struct opkg_opk_dirent *dirent, char **cur,
return NULL;
}
- **cur = '/';
- *cur += 1;
- memcpy(*cur, dirent->name, len - 1);
- *cur += len - 1;
+ if (dirent->parent != NULL) {
+ **cur = '/';
+ *cur += 1;
+ --len;
+ }
+ memcpy(*cur, dirent->name, len);
+ *cur += len;
return buf;
}