aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2022-08-22 09:13:00 +0300
committerJoursoir <chat@joursoir.net>2022-08-22 16:23:24 +0300
commit1ced9b35b040714bf4bbf3fab8d5f9e8170d50a5 (patch)
tree9435ee831dbed90ed6018caeb7247450fb13e249
parent70a5a003747c26412b2d89afe180de6fc8e8d423 (diff)
downloadlock-password-1ced9b35b040714bf4bbf3fab8d5f9e8170d50a5.tar.gz
lock-password-1ced9b35b040714bf4bbf3fab8d5f9e8170d50a5.tar.bz2
lock-password-1ced9b35b040714bf4bbf3fab8d5f9e8170d50a5.zip
cmd_insert: replace errprint_*() with print_error()
Handle errors using goto instead of "do { ... } while(0)". This is one of the steps on the way to get rid of errprint_*() macros and handle errors by yourself. For more context see other patches under the same topic specified below. TOPIC=drop_errprint
-rw-r--r--src/exec-cmd.c87
1 files changed, 45 insertions, 42 deletions
diff --git a/src/exec-cmd.c b/src/exec-cmd.c
index 621acd1..5ad312c 100644
--- a/src/exec-cmd.c
+++ b/src/exec-cmd.c
@@ -95,8 +95,10 @@ int cmd_insert(int argc, char *argv[])
}
result = check_sneaky_paths(path);
- if(result)
- errprint_r(1, "You have used forbidden paths\n");
+ if(result) {
+ print_error("Error: You have used forbidden paths\n");
+ return 1;
+ }
if(file_exist(path) == F_ISFILE) {
if(!flag_force) {
@@ -106,53 +108,54 @@ int cmd_insert(int argc, char *argv[])
}
char *f_pass, *s_pass;
- do { // START DO
-
- if(!flag_echo) {
- visible_enter(0);
-
- printf("Type your password: ");
- f_pass = get_input(minlen_pass, maxlen_pass);
- printf("\n");
- if(f_pass == NULL) {
- errprint_ptr(&retval, 1, "Incorrect password\n");
- break;
- }
-
- printf("Type your password again: ");
- s_pass = get_input(minlen_pass, maxlen_pass);
- printf("\n");
- if(s_pass == NULL) {
- errprint_ptr(&retval, 1, "Incorrect password\n");
- break;
- }
-
- if(strcmp(f_pass, s_pass) != 0) {
- errprint_ptr(&retval, 1, "Password do not match\n");
- break;
- }
+ if(!flag_echo) {
+ visible_enter(0);
+
+ printf("Type your password: ");
+ f_pass = get_input(minlen_pass, maxlen_pass);
+ printf("\n");
+ if(f_pass == NULL) {
+ print_error("Error: Incorrect password\n");
+ retval = 1;
+ goto out;
}
- else {
- printf("Type your password: ");
- f_pass = get_input(minlen_pass, maxlen_pass);
- if(f_pass == NULL) {
- errprint_ptr(&retval, 1, "Incorrect password\n");
- break;
- }
+
+ printf("Type your password again: ");
+ s_pass = get_input(minlen_pass, maxlen_pass);
+ printf("\n");
+ if(s_pass == NULL) {
+ print_error("Error: Incorrect password\n");
+ retval = 1;
+ goto out;
}
- result = insert_pass(path, f_pass);
- if(result) {
- errprint_ptr(&retval, 1, "Can't add password to LockPassword\n");
- break;
+ if(strcmp(f_pass, s_pass) != 0) {
+ print_error("Error: Password do not match\n");
+ retval = 1;
+ goto out;
+ }
+ }
+ else {
+ printf("Type your password: ");
+ f_pass = get_input(minlen_pass, maxlen_pass);
+ if(f_pass == NULL) {
+ print_error("Error: Incorrect password\n");
+ return 1;
}
- if(flag_copy)
- copy_outside(f_pass);
+ }
- printf("Password added successfully for %s\n", path);
+ result = insert_pass(path, f_pass);
+ if(result) {
+ print_error("Error: Can't add password to LockPassword\n");
+ retval = 1;
+ goto out;
+ }
+ if(flag_copy)
+ copy_outside(f_pass);
- } while(0); // END DO
+ printf("Password added successfully for %s\n", path);
+out:
visible_enter(1);
if(f_pass)
free(f_pass);