diff options
author | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-04-25 05:24:35 +0000 |
---|---|---|
committer | vapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2005-04-25 05:24:35 +0000 |
commit | bc88556f14f3b8ba1115b2e9687b059bade60865 (patch) | |
tree | 5f7aa8b3884f523eea53f35e69a77362ca352235 | |
parent | 8d75c438ed1b83c2cf470d959db38bb481fad936 (diff) | |
download | busybox-w32-bc88556f14f3b8ba1115b2e9687b059bade60865.tar.gz busybox-w32-bc88556f14f3b8ba1115b2e9687b059bade60865.tar.bz2 busybox-w32-bc88556f14f3b8ba1115b2e9687b059bade60865.zip |
use asprintf in place of malloc/sprintf as suggested by solar
git-svn-id: svn://busybox.net/trunk/busybox@10179 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | e2fsprogs/chattr.c | 8 | ||||
-rw-r--r-- | e2fsprogs/lsattr.c | 18 |
2 files changed, 13 insertions, 13 deletions
diff --git a/e2fsprogs/chattr.c b/e2fsprogs/chattr.c index 5aaa14fbb..07cee8f7c 100644 --- a/e2fsprogs/chattr.c +++ b/e2fsprogs/chattr.c | |||
@@ -167,11 +167,9 @@ static int chattr_dir_proc(const char *dir_name, struct dirent *de, | |||
167 | /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ | 167 | /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/ |
168 | if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ | 168 | if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \ |
169 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { | 169 | (de->d_name[1] == '.' && de->d_name[2] == '\0'))) { |
170 | 170 | char *path; | |
171 | char *path = malloc(strlen(dir_name) + 1 + strlen(de->d_name) + 1); | 171 | if (asprintf(&path, "%s/%s", dir_name, de->d_name) == -1) |
172 | if (!path) | 172 | bb_error_msg_and_die("asprintf failed"); |
173 | bb_error_msg_and_die("Couldn't allocate path variable in chattr_dir_proc"); | ||
174 | sprintf(path, "%s/%s", dir_name, de->d_name); | ||
175 | change_attributes(path); | 173 | change_attributes(path); |
176 | free(path); | 174 | free(path); |
177 | } | 175 | } |
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, | |||
101 | { | 101 | { |
102 | STRUCT_STAT st; | 102 | STRUCT_STAT st; |
103 | char *path; | 103 | char *path; |
104 | int dir_len = strlen(dir_name); | 104 | int i = strlen(dir_name); |
105 | 105 | ||
106 | path = malloc(dir_len + strlen(de->d_name) + 2); | 106 | if (i && dir_name[i-1] == '/') |
107 | 107 | i = asprintf(&path, "%s%s", dir_name, de->d_name); | |
108 | if (dir_len && dir_name[dir_len-1] == '/') | ||
109 | sprintf(path, "%s%s", dir_name, de->d_name); | ||
110 | else | 108 | else |
111 | sprintf(path, "%s/%s", dir_name, de->d_name); | 109 | i = asprintf(&path, "%s/%s", dir_name, de->d_name); |
110 | if (i == -1) | ||
111 | bb_perror_msg_and_die("asprintf failed"); | ||
112 | |||
112 | if (LSTAT(path, &st) == -1) | 113 | if (LSTAT(path, &st) == -1) |
113 | bb_perror_msg(path); | 114 | bb_perror_msg(path); |
114 | else { | 115 | else { |
115 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { | 116 | if (de->d_name[0] != '.' || (flags & OPT_ALL)) { |
116 | list_attributes(path); | 117 | list_attributes(path); |
117 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && | 118 | if (S_ISDIR(st.st_mode) && (flags & OPT_RECUR) && |
118 | strcmp(de->d_name, ".") && | 119 | strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) { |
119 | strcmp(de->d_name, "..")) { | ||
120 | printf("\n%s:\n", path); | 120 | printf("\n%s:\n", path); |
121 | iterate_on_dir(path, lsattr_dir_proc, NULL); | 121 | iterate_on_dir(path, lsattr_dir_proc, NULL); |
122 | printf("\n"); | 122 | printf("\n"); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | } | 125 | } |
126 | |||
126 | free(path); | 127 | free(path); |
128 | |||
127 | return 0; | 129 | return 0; |
128 | } | 130 | } |
129 | 131 | ||