From 7b3313e21cf2011761a4d8658713a95659540318 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Thu, 11 May 2023 04:50:25 -0400 Subject: dirent: Add trailing '/' to directories --- (limited to 'src/dirent.c') 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; } -- cgit v0.9.1