aboutsummaryrefslogtreecommitdiffstats
path: root/easydir.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-10-31 17:45:29 +0000
committerJoursoir <chat@joursoir.net>2020-10-31 17:45:29 +0000
commit64ef51a8ce6bc148ba493e350e2cac4cba470201 (patch)
tree4418c4133b16341975cfe4d29df8da6ce27abcff /easydir.c
parent38a3be4a3eeacec75a534fef6951b9484b4d7098 (diff)
downloadlock-password-64ef51a8ce6bc148ba493e350e2cac4cba470201.tar.gz
lock-password-64ef51a8ce6bc148ba493e350e2cac4cba470201.tar.bz2
lock-password-64ef51a8ce6bc148ba493e350e2cac4cba470201.zip
some features:
remake README.md for new code architecture; add help command; add man page;
Diffstat (limited to 'easydir.c')
-rw-r--r--easydir.c79
1 files changed, 0 insertions, 79 deletions
diff --git a/easydir.c b/easydir.c
deleted file mode 100644
index 162bae7..0000000
--- a/easydir.c
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/wait.h>
-#include <errno.h>
-
-#include "handerror.h"
-
-int deleteFile(char *file_path)
-{
- char *arguments[] = {"rm", file_path, NULL};
- easyFork("rm", arguments);
-
- return 1;
-}
-
-int deleteEmptyDir(char *dir_path)
-{
- #if defined(DEBUG)
- char *arguments[] = {"rmdir", "-p", dir_path, NULL};
- #else
- char *arguments[] = {"rmdir", "-p", "--ignore-fail-on-non-empty", dir_path, NULL};
- #endif
- easyFork("rmdir", arguments);
-
- return 1;
-}
-
-int checkFileExist(char *path_to_file)
-{
- FILE *pFile;
-
- pFile = fopen(path_to_file, "r+"); // r+ so that errno can equal EISDIR
- if(pFile == NULL) {
- if(errno == ENOENT) // file doesn't exist
- return 0;
- if(errno == EISDIR) // it's directory
- return 2;
- else callError(120);
- }
- fclose(pFile);
-
- return 1;
-}
-
-char *fileCropLineFeed(char *path, char *text, int maxlen)
-{
- FILE *file = fopen(path, "r+");
- if(file == NULL) callError(130);
-
- int symbol;
- int pos = 0;
- char *str = (char *) malloc(sizeof(char) * maxlen);
- while((symbol = fgetc(file)))
- {
- switch(symbol)
- {
- case '\n':
- case EOF: {
- str[pos] = '\0';
- pos = -1; // for break while
- break;
- }
- default: {
- str[pos] = symbol;
- pos++;
- break;
- }
- }
- if(pos == -1) break;
- if(pos > maxlen-1) { str[pos-1] = '\0'; break; }
- }
- fclose(file);
-
- strcpy(text, str);
- free(str);
- return text;
-}