git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15592 27425a3e-05d8-49a3-a47f-9c15f0e5edd8

This commit is contained in:
Giovanni Di Sirio 2022-04-22 11:51:48 +00:00
parent aecddb8a9e
commit b6aa2da1b4
1 changed files with 19 additions and 10 deletions

View File

@ -36,13 +36,21 @@ static bool lflg = false;
static bool qflg = false;
struct afile {
char ftype;
short fnlink;
mode_t fflags;
off_t fsize;
char *fname;
char ftype;
long fnum;
short fnlink;
mode_t fflags;
off_t fsize;
char *fname;
};
#define ISARG 0x8000 /* extra ``mode'' */
struct subdirs {
char *sd_name;
struct subdirs *sd_next;
} *subdirs;
static void usage(void) {
fprintf(stderr, "Usage: ls [<opts>] [<file>]..." NEWLINE_STR);
fprintf(stderr, "Options:" NEWLINE_STR);
@ -404,7 +412,7 @@ static void formatd(char *name, int title) {
if (fp->ftype != 'd' || !strcmp(fp->fname, ".")
|| !strcmp(fp->fname, ".."))
continue;
dp = (struct subdirs*)malloc(sizeof(struct subdirs));
dp = (struct subdirs *)malloc(sizeof(struct subdirs));
if (dp == 0L) { /*PATCH GIOV.*/
fprintf(stderr, "ls: out of memory\n");
exit(1);
@ -416,8 +424,8 @@ static void formatd(char *name, int title) {
for (fp = dfp0; fp < dfplast; fp++) {
if ((fp->fflags & ISARG) == 0 && fp->fname)
free(fp->fname);
if (fp->flinkto)
free(fp->flinkto);
// if (fp->flinkto)
// free(fp->flinkto);
}
free((char*)dfp0);
}
@ -485,16 +493,17 @@ int main(int argc, char *argv[], char *envp[]) {
/* Allocating a single big buffer for all files.*/
bufp = calloc(argc, sizeof (struct afile));
fp0 = (struct afile *)bufp;
fp = (struct afile *)bufp;
if (bufp == NULL) {
error("out of memory");
}
/* Scanning all arguments and populating the array.*/
fp = fp0;
fp0 = fp;
for (i = 0; i < argc; i++) {
if (!gstat(fp, *argv, true)) {
fp->fname = *argv;
fp->fflags |= ISARG;
fp++;
}
argv++;