summaryrefslogtreecommitdiff
path: root/command/ls.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-05-14 21:43:02 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-05-14 21:43:02 -0400
commite735ad6710a82604a206ad29f6cbcdd7dc4b024c (patch)
tree5fe8eebbb7a2bff20bb71bd2368955356979e0a2 /command/ls.c
parentsync (diff)
downloadlazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.tar.gz
lazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.tar.bz2
lazysphere-e735ad6710a82604a206ad29f6cbcdd7dc4b024c.zip
refactor and add su
Diffstat (limited to 'command/ls.c')
-rw-r--r--command/ls.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/command/ls.c b/command/ls.c
index bbfedfb..d4d19c1 100644
--- a/command/ls.c
+++ b/command/ls.c
@@ -66,9 +66,9 @@ static DIR* get_directory(char* path) {
DIR* d = opendir(path);
if (d == NULL) {
if (errno == ENOTDIR) {
- error_s("`%s` is a a file\n", path);
+ error_s("`%s` is a a file", path);
} else {
- error_s("failed to open directory '%s': %s\n", path, strerror(errno));
+ error_s("failed to open directory '%s'", path);
}
}
return d;
@@ -90,7 +90,7 @@ static bool get_file_info(const char* file_name, struct FileInfo* info) {
save = push_path_buffer(file_name);
if (lstat(get_path_buffer(), &s) < 0) {
- error_s("failed to read file '%s': %s\n", get_path_buffer(), strerror(errno));
+ error_s("failed to read file '%s'", get_path_buffer());
pop_path_buffer(save);
return false;
}
@@ -199,7 +199,7 @@ static bool get_file_info(const char* file_name, struct FileInfo* info) {
info->type = ty;
file_len = strlen(file_name) + 1;
- info->name = malloc(file_len);
+ info->name = xalloc(file_len);
memcpy(info->name, file_name, file_len);
print_file_size(s.st_size, info->size);
@@ -340,7 +340,7 @@ static void push_file(
if (*size == *capacity) {
*capacity *= 2;
- *files = realloc(*files, sizeof(struct FileInfo) * *capacity);
+ *files = xrealloc(*files, sizeof(struct FileInfo) * *capacity);
}
user_len = strlen(finfo.usr->pw_name);
@@ -382,7 +382,7 @@ static void recurse_directory(char* dir_name) {
capacity = 8;
size = 0;
- files = malloc(sizeof(struct FileInfo) * capacity);
+ files = xalloc(sizeof(struct FileInfo) * capacity);
memset(&info, 0, sizeof(struct FileListInfo));
while((file = readdir(d)) != NULL) {
@@ -434,7 +434,7 @@ static void list_directory(char* path) {
capacity = 8;
size = 0;
- files = malloc(sizeof(struct FileInfo) * capacity);
+ files = xalloc(sizeof(struct FileInfo) * capacity);
memset(&info, 0, sizeof(struct FileListInfo));
while ((file = readdir(d)) != NULL) {
@@ -466,7 +466,7 @@ static void list_file_args(int start, int argc, char** argv) {
capacity = 8;
size = 0;
- files = malloc(sizeof(struct FileInfo) * capacity);
+ files = xalloc(sizeof(struct FileInfo) * capacity);
memset(&info, 0, sizeof(struct FileListInfo));
for (i = start; i < argc; i++) {