summaryrefslogtreecommitdiff
path: root/usr/src/common
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2019-04-19 21:47:32 +0300
committerToomas Soome <tsoome@me.com>2019-05-15 10:05:15 +0300
commitd9c27481e4cab76c5b1c7abf01b386f487b83573 (patch)
tree1b624222f4473162097b15f6ad9fd4e5719911c3 /usr/src/common
parent7edfb5b07f43089085e704c276e1a7a0cb1cd32b (diff)
downloadillumos-joyent-d9c27481e4cab76c5b1c7abf01b386f487b83573.tar.gz
10831 loader emulator ls command fails to detect file types
Reviewed by: Igor Kozhukhov <igor@dilos.org> Reviewed by: Youzhong Yang <youzhong@gmail.com> Reviewed by: Andy Fiddaman <andy@omniosce.org> Approved by: Dan McDonald <danmcd@joyent.com>
Diffstat (limited to 'usr/src/common')
-rw-r--r--usr/src/common/ficl/emu/loader_emu.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/usr/src/common/ficl/emu/loader_emu.c b/usr/src/common/ficl/emu/loader_emu.c
index dcb2933b84..c3ebb3f21f 100644
--- a/usr/src/common/ficl/emu/loader_emu.c
+++ b/usr/src/common/ficl/emu/loader_emu.c
@@ -1552,20 +1552,19 @@ command_ls(int argc, char *argv[])
while ((d = readdir(dir)) != NULL) {
if (strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) {
/* stat the file, if possible */
- sb.st_size = 0;
- sb.st_mode = 0;
- buf = malloc(strlen(path) + strlen(d->d_name) + 2);
if (path[0] == '\0') {
- (void) snprintf(buf, sizeof (buf), "%s",
- d->d_name);
+ (void) asprintf(&buf, "%s", d->d_name);
} else {
- (void) snprintf(buf, sizeof (buf), "%s/%s",
- path, d->d_name);
+ (void) asprintf(&buf, "%s/%s", path, d->d_name);
+ }
+ if (buf != NULL) {
+ /* ignore return, could be symlink, etc. */
+ if (stat(buf, &sb)) {
+ sb.st_size = 0;
+ sb.st_mode = 0;
+ }
+ free(buf);
}
- /* ignore return, could be symlink, etc. */
- if (stat(buf, &sb))
- sb.st_size = 0;
- free(buf);
if (verbose) {
(void) snprintf(lbuf, sizeof (lbuf),
" %c %8d %s\n",