From 5dbba2a2cc59e44b8370429a9573d440b9daffcc Mon Sep 17 00:00:00 2001 From: Oskar Date: Sat, 20 Apr 2024 17:03:08 +0200 Subject: Fixed issue with the file/directory check --- startmode.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'startmode.c') diff --git a/startmode.c b/startmode.c index 645616d..57e45a6 100644 --- a/startmode.c +++ b/startmode.c @@ -113,14 +113,6 @@ int fe_stop = 0; int startmode(char filename[]) { - struct stat sb; - stat(filename, &sb); - - if (sb.st_mode & S_IFDIR) { // check if its a directory - fprintf(stderr, "This is a directory\n"); - exit(EXIT_FAILURE); - } - uint8_t file_existence = check_if_file_exists(filename); if (fe_stop == 0) { if (file_existence == FILE_NOT_FOUND) { @@ -131,6 +123,15 @@ int startmode(char filename[]) { fclose(file); } } + + struct stat sb; + stat(filename, &sb); + + if (sb.st_mode & S_IFDIR) { // check if its a directory + fprintf(stderr, "This is a directory\n"); + exit(EXIT_FAILURE); + } + // The entry to the program. Count lines and display the count. Also show which file is being edited. uint64_t Flines; -- cgit v1.2.3