diff options
author | jozan <jozan@noemail.net> | 2020-11-05 21:11:00 +0000 |
---|---|---|
committer | jozan <jozan@noemail.net> | 2020-11-05 21:11:00 +0000 |
commit | a08a005acbca938722f7071686bb47a3729260d3 (patch) | |
tree | 555a71a626afc9a1af406259e576255276cd9f39 | |
parent | Reading in progress (diff) | |
download | unixize-a08a005acbca938722f7071686bb47a3729260d3.tar.gz unixize-a08a005acbca938722f7071686bb47a3729260d3.tar.bz2 unixize-a08a005acbca938722f7071686bb47a3729260d3.tar.xz unixize-a08a005acbca938722f7071686bb47a3729260d3.tar.zst unixize-a08a005acbca938722f7071686bb47a3729260d3.zip |
Correctly parsed file names
FossilOrigin-Name: 980ba03855e22bc2773667472adb0eb0d440b8aa8519b1217c4c938109636c32
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/c_lfiles.c | 17 | ||||
-rw-r--r-- | src/c_unixize.c | 23 | ||||
-rw-r--r-- | src/c_unixize.h | 8 |
4 files changed, 34 insertions, 16 deletions
@@ -16,7 +16,7 @@ # # GNU Makefile -.DEFAULT_GOAL := msan +.DEFAULT_GOAL := asan SHELL := /bin/sh DESTDIR = /usr/local diff --git a/src/c_lfiles.c b/src/c_lfiles.c index af13a39..f39c330 100644 --- a/src/c_lfiles.c +++ b/src/c_lfiles.c @@ -45,6 +45,8 @@ * In this files are functions to handle the files linked list. */ +#include <sys/param.h> + #include <dirent.h> #include <errno.h> #include <stdio.h> @@ -99,16 +101,16 @@ c_lfiles_new { struct lfiles_s* link; - link = (struct lfiles_s*)malloc(sizeof(struct lfiles_s*)); + link = (struct lfiles_s*)malloc(sizeof(struct lfiles_s)); if (link == NULL) { return (NULL); } link->filename = strdup(filename); - link->filetype = filetype; if (link->filename == NULL) { u_memdel((void*)&link); return (NULL); } + link->filetype = filetype; link->next = NULL; return (link); } @@ -131,10 +133,19 @@ c_lfiles_gather(void) struct dirent* dp; struct lfiles_s* head; struct lfiles_s* link; + char path[MAXPATHLEN]; head = NULL; link = NULL; - dirp = opendir("."); + if (getcwd(path, MAXPATHLEN) == NULL) { + dprintf( + STDERR_FILENO, + "unixize: %s\n", + strerror(errno) + ); + return (NULL); + } + dirp = opendir(path); if (dirp == NULL) { dprintf( STDERR_FILENO, diff --git a/src/c_unixize.c b/src/c_unixize.c index 9f4dbde..85f020f 100644 --- a/src/c_unixize.c +++ b/src/c_unixize.c @@ -45,8 +45,11 @@ * This is the main function and entrypoint of the program. */ +#include <errno.h> #include <stdio.h> #include <stddef.h> +#include <string.h> +#include <unistd.h> #include "c_lfiles.h" #include "c_opts.h" @@ -57,17 +60,25 @@ main const char* argv[]) { struct opts_s opts; - struct lfiles_s* files; + struct lfiles_s* og_files; + struct lfiles_s* new_files; c_get_opts(&opts, argc, argv); - files = c_lfiles_gather(); - if (files == NULL) { + if (chdir((const char*)opts.dir) == -1) { + dprintf( + STDERR_FILENO, + "unixize: %s\n", + strerror(errno) + ); return (1); } - while (files != NULL) { - printf("'%s' - %hhu\n", files->filename, files->filetype); - files = files->next; + og_files = c_lfiles_gather(); + new_files = c_lfiles_duplicate(og_files); + if (og_files == NULL) { + return (1); } + c_lfiles_clear(&og_files); + c_lfiles_clear(&new_files); return (0); } diff --git a/src/c_unixize.h b/src/c_unixize.h index edf9cde..a43f887 100644 --- a/src/c_unixize.h +++ b/src/c_unixize.h @@ -46,11 +46,7 @@ #ifndef __C_UNIXIZE_H__ #define __C_UNIXIZE_H__ -#ifdef __linux__ -#include <linux/limits.h> -#else -#include <limits.h> -#endif +#include <sys/param.h> typedef enum bool_e { FALSE, @@ -63,7 +59,7 @@ struct opts_s { bool_t pretend; bool_t recursive; bool_t verbose; - char dir[PATH_MAX]; + char dir[MAXPATHLEN]; }; struct lfiles_s { |