aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/lsattr.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2005-04-25 05:24:35 +0000
committerMike Frysinger <vapier@gentoo.org>2005-04-25 05:24:35 +0000
commitc238a97a9e90734da15163ba54d6862bb8e360e9 (patch)
tree5f7aa8b3884f523eea53f35e69a77362ca352235 /e2fsprogs/lsattr.c
parent7eb6457c4cf76ace4e738c01911c78ec52e51840 (diff)
downloadbusybox-c238a97a9e90734da15163ba54d6862bb8e360e9.tar.gz
use asprintf in place of malloc/sprintf as suggested by solar
Diffstat (limited to 'e2fsprogs/lsattr.c')
-rw-r--r--e2fsprogs/lsattr.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c
index be5723c43..d3896637d 100644
--- a/e2fsprogs/lsattr.c
+++ b/e2fsprogs/lsattr.c
@@ -101,29 +101,31 @@ static int lsattr_dir_proc(const char *dir_name, struct dirent *de,
{
STRUCT_STAT st;
char *path;
- int dir_len = strlen(dir_name);
+ int i = strlen(dir_name);
- path = malloc(dir_len + strlen(de->d_name) + 2);
-
- if (dir_len && dir_name[dir_len-1] == '/')
- sprintf(path, "%s%s", dir_name, de->d_name);
+ if (i && dir_name[i-1] == '/')
+ i = asprintf(&path, "%s%s", dir_name, de->d_name);
else
- sprintf(path, "%s/%s", dir_name, de->d_name);
+ i = asprintf(&path, "%s/%s", dir_name, de->d_name);
+ if (i == -1)
+ bb_perror_msg_and_die("asprintf failed");
+
if (LSTAT(path, &st) == -1)
bb_perror_msg(path);
else {
if (de->d_name[0] != '.' || (flags & OPT_ALL)) {
list_attributes(path);
if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) &&
- strcmp(de->d_name, ".") &&
- strcmp(de->d_name, "..")) {
+ strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {
printf("\n%s:\n", path);
iterate_on_dir(path, lsattr_dir_proc, NULL);
printf("\n");
}
}
}
+
free(path);
+
return 0;
}