aboutsummaryrefslogtreecommitdiffstats
path: root/easydir.c
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2020-10-26 19:11:16 +0000
committerJoursoir <chat@joursoir.net>2020-10-26 19:11:16 +0000
commit101dd376b32c2cd12640e81b93c2f30975baac7f (patch)
tree8f571472aefb58274755e3dd6778497564554edc /easydir.c
parent5f3bbf1279d39554cd2d185170ae4e5119cf3b61 (diff)
downloadlock-password-101dd376b32c2cd12640e81b93c2f30975baac7f.tar.gz
lock-password-101dd376b32c2cd12640e81b93c2f30975baac7f.tar.bz2
lock-password-101dd376b32c2cd12640e81b93c2f30975baac7f.zip
feature: edit command
Diffstat (limited to 'easydir.c')
-rw-r--r--easydir.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/easydir.c b/easydir.c
index 08cac0f..9337fe1 100644
--- a/easydir.c
+++ b/easydir.c
@@ -42,3 +42,37 @@ int checkFileExist(char *path_to_file)
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;
+}