Page MenuHomeFreeBSD

D10066.id26468.diff
No OneTemporary

D10066.id26468.diff

Index: sys/boot/common/ls.c
===================================================================
--- sys/boot/common/ls.c
+++ sys/boot/common/ls.c
@@ -91,6 +91,18 @@
path = argv[1];
}
+ if (stat(path, &sb) == 0 && !S_ISDIR(sb.st_mode)) {
+ if (verbose) {
+ printf(" %c %8d %s\n",
+ typestr[sb.st_mode >> 12],
+ (int)sb.st_size, path);
+ } else {
+ printf(" %c %s\n",
+ typestr[sb.st_mode >> 12], path);
+ }
+ return (CMD_OK);
+ }
+
fd = ls_getdir(&path);
if (fd == -1) {
result = CMD_ERROR;
@@ -102,19 +114,28 @@
while ((d = readdirfd(fd)) != NULL) {
if (strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) {
- if (verbose) {
+ if (d->d_type == 0 || verbose) {
/* stat the file, if possible */
sb.st_size = 0;
+ sb.st_mode = 0;
buf = malloc(strlen(path) + strlen(d->d_name) + 2);
- sprintf(buf, "%s/%s", path, d->d_name);
- /* ignore return, could be symlink, etc. */
- if (stat(buf, &sb))
- sb.st_size = 0;
- free(buf);
- sprintf(lbuf, " %c %8d %s\n", typestr[d->d_type],
+ if (buf != NULL) {
+ sprintf(buf, "%s/%s", path, d->d_name);
+ /* ignore return, could be symlink, etc. */
+ if (stat(buf, &sb)) {
+ sb.st_size = 0;
+ sb.st_mode = 0;
+ }
+ free(buf);
+ }
+ }
+ if (verbose) {
+ snprintf(lbuf, sizeof(lbuf), " %c %8d %s\n",
+ typestr[d->d_type? d->d_type:sb.st_mode >> 12],
(int)sb.st_size, d->d_name);
} else {
- sprintf(lbuf, " %c %s\n", typestr[d->d_type], d->d_name);
+ snprintf(lbuf, sizeof(lbuf), " %c %s\n",
+ typestr[d->d_type? d->d_type:sb.st_mode >> 12], d->d_name);
}
if (pager_output(lbuf))
goto out;
@@ -124,8 +145,7 @@
pager_close();
if (fd != -1)
close(fd);
- if (path != NULL)
- free(path);
+ free(path); /* ls_getdir() did allocate path */
return(result);
}
@@ -139,9 +159,8 @@
struct stat sb;
int fd;
const char *cp;
- char *path, *tail;
+ char *path;
- tail = NULL;
fd = -1;
/* one extra byte for a possible trailing slash required */

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 22, 12:37 AM (11 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25844821
Default Alt Text
D10066.id26468.diff (2 KB)

Event Timeline