Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F137030400
D10066.id26486.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D10066.id26486.diff
View Options
Index: sys/boot/common/ls.c
===================================================================
--- sys/boot/common/ls.c
+++ sys/boot/common/ls.c
@@ -65,21 +65,21 @@
char lbuf[128]; /* one line */
int result, ch;
int verbose;
-
+
result = CMD_OK;
fd = -1;
verbose = 0;
optind = 1;
optreset = 1;
while ((ch = getopt(argc, argv, "l")) != -1) {
- switch(ch) {
+ switch (ch) {
case 'l':
verbose = 1;
break;
case '?':
default:
/* getopt has already reported an error */
- return(CMD_OK);
+ return (CMD_OK);
}
}
argv += (optind - 1);
@@ -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,9 +145,8 @@
pager_close();
if (fd != -1)
close(fd);
- if (path != NULL)
- free(path);
- return(result);
+ free(path); /* ls_getdir() did allocate path */
+ return (result);
}
/*
@@ -139,13 +159,17 @@
struct stat sb;
int fd;
const char *cp;
- char *path, *tail;
-
- tail = NULL;
+ char *path;
+
fd = -1;
/* one extra byte for a possible trailing slash required */
path = malloc(strlen(*pathp) + 2);
+ if (path == NULL) {
+ snprintf(command_errbuf, sizeof (command_errbuf),
+ "out of memory");
+ goto out;
+ }
strcpy(path, *pathp);
/* Make sure the path is respectable to begin with */
@@ -154,7 +178,7 @@
"bad path '%s'", path);
goto out;
}
-
+
/* If there's no path on the device, assume '/' */
if (*cp == 0)
strcat(path, "/");
@@ -177,12 +201,12 @@
}
*pathp = path;
- return(fd);
+ return (fd);
out:
free(path);
*pathp = NULL;
if (fd != -1)
close(fd);
- return(-1);
+ return (-1);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 22, 12:39 AM (16 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25845470
Default Alt Text
D10066.id26486.diff (3 KB)
Attached To
Mode
D10066: loader: ls command should display file types properly
Attached
Detach File
Event Timeline
Log In to Comment