summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dirent.c25
-rw-r--r--src/dirent.h5
-rw-r--r--src/ustar.c2
3 files changed, 18 insertions, 14 deletions
diff --git a/src/dirent.c b/src/dirent.c
index f0377c8..9f29235 100644
--- a/src/dirent.c
+++ b/src/dirent.c
@@ -24,8 +24,9 @@
#include "dirent.h"
static int
-_opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char **name_buf,
- size_t *name_buf_len, char **pref_buf, size_t *pref_buf_len,
+_opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, int is_dir,
+ char **name_buf, size_t *name_buf_len,
+ char **pref_buf, size_t *pref_buf_len,
size_t *name_len, size_t *pref_len)
{
size_t len;
@@ -33,9 +34,9 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char **name_buf,
int sep;
len = strlen(dirent->name);
- if (*name_len > 0 && *name_len + len + 1 <= *name_buf_len) {
- /* Space available in name buffer. Not last node, so append
- * separator. */
+ if ((*name_len > 0 || is_dir) && *name_len + len + 1 <= *name_buf_len) {
+ /* Space available in name buffer. Not last node, or is a
+ * directory, so append separator. */
buf = name_buf;
*name_len += len + 1;
sep = 1;
@@ -68,7 +69,7 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char **name_buf,
/* Recurse. */
if (dirent->parent != NULL &&
- _opkg_opk_dirent_name_prefix(dirent->parent,
+ _opkg_opk_dirent_name_prefix(dirent->parent, is_dir,
name_buf, name_buf_len, pref_buf, pref_buf_len,
name_len, pref_len) == OPKG_OPK_ERROR) {
return OPKG_OPK_ERROR;
@@ -86,8 +87,9 @@ _opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char **name_buf,
}
int
-opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char *name_buf,
- size_t name_buf_len, char *pref_buf, size_t pref_buf_len)
+opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, int is_dir,
+ char *name_buf, size_t name_buf_len,
+ char *pref_buf, size_t pref_buf_len)
{
size_t name_len = 0;
size_t pref_len = 0;
@@ -98,9 +100,10 @@ opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char *name_buf,
--name_buf_len;
--pref_buf_len;
- if (_opkg_opk_dirent_name_prefix(dirent, &name_buf, &name_buf_len,
- &pref_buf, &pref_buf_len, &name_len, &pref_len)
- == OPKG_OPK_ERROR) {
+ if (_opkg_opk_dirent_name_prefix(dirent, is_dir,
+ &name_buf, &name_buf_len,
+ &pref_buf, &pref_buf_len,
+ &name_len, &pref_len) == OPKG_OPK_ERROR) {
return OPKG_OPK_ERROR;
}
diff --git a/src/dirent.h b/src/dirent.h
index 4cce24f..d41a138 100644
--- a/src/dirent.h
+++ b/src/dirent.h
@@ -26,7 +26,8 @@ struct opkg_opk_dirent {
};
int
-opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, char *name_buf,
- size_t name_len, char *pref_buf, size_t pref_len);
+opkg_opk_dirent_name_prefix(struct opkg_opk_dirent *dirent, int is_dir,
+ char *name_buf, size_t name_buf_len,
+ char *pref_buf, size_t pref_buf_len);
#endif /* OPKG_OPK_DIRENT_H_ */
diff --git a/src/ustar.c b/src/ustar.c
index 7ad7da8..359f967 100644
--- a/src/ustar.c
+++ b/src/ustar.c
@@ -288,7 +288,7 @@ opkg_opk_ustar_write_header(struct opkg_opk_ustar *ustar,
memset(&ustar->header, 0, sizeof(ustar->header));
- if (opkg_opk_dirent_name_prefix(dirent,
+ if (opkg_opk_dirent_name_prefix(dirent, (type == 'd' ? 1 : 0),
ustar->header.name,
sizeof(ustar->header.name),
ustar->header.prefix,