This commit is contained in:
usr 2024-04-12 18:59:13 +03:00
parent 0640e58135
commit 57e466888a
2 changed files with 23 additions and 15 deletions

View File

@ -29,7 +29,7 @@ for project in $projects; do
env CC=$CC CFLAGS="$CFLAGS -I$PROJECT_DIR -I$PROJECT_DIR/include/libmu" OUTPUT="$PROJECT_DIR"/bin/ ./build.sh
cd $PROJECT_DIR
done
echo -n "\n"
echo -ne "\n"
done
done

View File

@ -68,24 +68,14 @@ struct d_node *stat_file(char *filename, int lfile) {
}
struct d_node **list(const char *path, size_t *nfiles, int *ret) {
struct stat sb;
if (mu_get_stat("ls", path, &sb))
return NULL;
struct d_node **dir = malloc((sb.st_nlink + 2) * sizeof(struct d_node));
if (dir == NULL) {
fprintf(stderr, "ls: malloc failed\n");
exit(1);
}
DIR *dp = opendir(path);
if (dp == NULL) {
free(dir);
fprintf(stderr, "ls: %s: %s\n", path, strerror(errno));
return NULL;
}
struct d_node *dn, *cur;
struct dirent *ep;
while ((ep = readdir(dp)) != NULL) {
if (ep->d_name[0] == '.' && !a_flag)
@ -95,17 +85,35 @@ struct d_node **list(const char *path, size_t *nfiles, int *ret) {
if (full_path == NULL)
continue;
dir[*nfiles] = stat_file(full_path, 0);
if (dir[*nfiles] == NULL) {
cur = stat_file(full_path, 0);
if (cur == NULL) {
*ret = 1;
free(full_path);
continue;
}
cur->next = dn;
dn = cur;
(*nfiles)++;
}
closedir(dp);
if (dn == NULL)
return NULL;
struct d_node **dir = malloc(*nfiles * sizeof(struct d_node *));
if (dir == NULL) {
fprintf(stderr, "ls: malloc failed\n");
return NULL;
}
for (int i = 0; i < *nfiles; i++) {
dir[i] = dn;
dn = dn->next;
}
return dir;
}