{
mode_t type;
const char *path;
+ size_t len;
type = archive_entry_filetype(entry);
path = archive_entry_pathname(entry);
if (path == NULL)
return (0);
- if (type == AE_IFDIR &&
- (path[0] == '\0' || path[strlen(path) - 1] != '/')) {
- return strlen(path) + 1;
- } else {
- return strlen(path);
- }
+ len = strlen(path);
+ if (type == AE_IFDIR && (path[0] == '\0' || path[len - 1] != '/'))
+ ++len; /* Space for the trailing / */
+ return len;
}
static int
memcpy(p, path, pathlen);
/* Folders are recognized by a trailing slash. */
- if ((type == AE_IFDIR) & (path[pathlen - 1] != '/')) {
+ if ((type == AE_IFDIR) && (path[pathlen - 1] != '/'))
p[pathlen] = '/';
- p[pathlen + 1] = '\0';
- }
}