aboutsummaryrefslogtreecommitdiff
path: root/lib/dir.c
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-04-01 17:38:32 -0700
committerChristian C <cc@localhost>2025-04-01 17:38:32 -0700
commita18cea2fef7aa1545c9a984b60919541b26a6f84 (patch)
treed1ab991e28b701bdfdc9035704389ad6c57391c9 /lib/dir.c
parent2bc54ac42b831a7dfcba26c2d12ba002f80a5e40 (diff)
Clang Format
Diffstat (limited to 'lib/dir.c')
-rw-r--r--lib/dir.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/lib/dir.c b/lib/dir.c
index be2a2ac..7200c52 100644
--- a/lib/dir.c
+++ b/lib/dir.c
@@ -1,11 +1,11 @@
-#include <lib/dir.h>
#include <dirent.h>
-#include <sys/stat.h>
-#include <string.h>
+#include <lib/dir.h>
#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
// Is directory
-bool_t is_directory(char* dirname) {
+bool_t is_directory(char *dirname) {
struct stat st;
if (stat(dirname, &st) == 0) {
if (S_ISDIR(st.st_mode)) {
@@ -16,11 +16,11 @@ bool_t is_directory(char* dirname) {
}
// List directory
-char** list_directory(char* dirname) {
+char **list_directory(char *dirname) {
DIR *d;
struct dirent *dir;
d = opendir(dirname);
- char** file_names = (char**)malloc(sizeof(char*));
+ char **file_names = (char **)malloc(sizeof(char *));
if (!file_names) {
return NULL;
}
@@ -29,15 +29,15 @@ char** list_directory(char* dirname) {
if (d) {
while ((dir = readdir(d)) != NULL) {
if (dir->d_type == DT_REG) {
- // When a regular file is reached
- /// Create space for it in the list
- file_names = realloc(file_names, (file_count+1+1)*sizeof(char*));
- /// Create space for the name
- file_names[file_count] = calloc(strlen(dir->d_name)+1, sizeof(char));
- /// Copy the name
- strcpy(file_names[file_count], dir->d_name);
- /// Mark the end of the file list with a NULL entry
- file_names[++file_count] = NULL;
+ // When a regular file is reached
+ /// Create space for it in the list
+ file_names = realloc(file_names, (file_count + 1 + 1) * sizeof(char *));
+ /// Create space for the name
+ file_names[file_count] = calloc(strlen(dir->d_name) + 1, sizeof(char));
+ /// Copy the name
+ strcpy(file_names[file_count], dir->d_name);
+ /// Mark the end of the file list with a NULL entry
+ file_names[++file_count] = NULL;
}
}
return file_names;
@@ -46,23 +46,22 @@ char** list_directory(char* dirname) {
}
// Get full path
-char* full_path(char* dir, char* file)
-{
- char* fpath = NULL;
+char *full_path(char *dir, char *file) {
+ char *fpath = NULL;
size_t dir_len = strlen(dir);
size_t file_len = strlen(file);
- fpath = (char*)calloc(dir_len+file_len+2,sizeof(char));
- strcpy(fpath,dir);
- strcpy(fpath+dir_len+1,file);
+ fpath = (char *)calloc(dir_len + file_len + 2, sizeof(char));
+ strcpy(fpath, dir);
+ strcpy(fpath + dir_len + 1, file);
fpath[dir_len] = '/';
return fpath;
}
// Determines if file name has tif file extension
-bool_t is_tif_ext(char* file_name)
-{
+bool_t is_tif_ext(char *file_name) {
size_t file_len = strlen(file_name);
- if ((file_name[file_len-3] == 't') && (file_name[file_len-2] == 'i') && (file_name[file_len-1] == 'f')) {
+ if ((file_name[file_len - 3] == 't') && (file_name[file_len - 2] == 'i') &&
+ (file_name[file_len - 1] == 'f')) {
return TRUE;
}
return FALSE;