summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2013-01-02 19:24:23 +0100
committerFelix Fietkau <nbd@openwrt.org>2013-01-02 19:46:17 +0100
commitdd8f306793db60a2d79c7618d012e0466c581bcf (patch)
tree100f84de2fc1710b8ea989c22a19bea0d8295b97 /file.c
parent4f8d550c72658177b47111d2f64dfe94900b6df4 (diff)
rework string handling for directory listing, avoid redundant string scanning
Diffstat (limited to 'file.c')
-rw-r--r--file.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/file.c b/file.c
index 22eb048..b46f0d6 100644
--- a/file.c
+++ b/file.c
@@ -462,14 +462,16 @@ static void uh_file_dirlist(struct client *cl, struct path_info *pi)
if ((count = scandir(pi->phys, &files, uh_file_scandir_filter_dir,
alphasort)) > 0)
{
- memset(filename, 0, sizeof(filename));
- memcpy(filename, pi->phys, sizeof(filename));
- pathptr = &filename[strlen(filename)];
+ int len;
+
+ strcpy(filename, pi->phys);
+ len = strlen(filename);
+ pathptr = filename + len;
+ len = PATH_MAX - len;
/* list subdirs */
for (i = 0; i < count; i++) {
- strncat(filename, files[i]->d_name,
- sizeof(filename) - strlen(files[i]->d_name));
+ snprintf(pathptr, len, "%s", files[i]->d_name);
if (!stat(filename, &s) &&
(s.st_mode & S_IFDIR) && (s.st_mode & S_IXOTH))
@@ -488,8 +490,7 @@ static void uh_file_dirlist(struct client *cl, struct path_info *pi)
/* list files */
for (i = 0; i < count; i++) {
- strncat(filename, files[i]->d_name,
- sizeof(filename) - strlen(files[i]->d_name));
+ snprintf(pathptr, len, "%s", files[i]->d_name);
if (!stat(filename, &s) &&
!(s.st_mode & S_IFDIR) && (s.st_mode & S_IROTH))