aboutsummaryrefslogtreecommitdiff
path: root/src/libnpass
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-04-17 07:22:44 +0530
committersinanmohd <sinan@sinanmohd.com>2024-04-17 07:30:00 +0530
commita6a49587035a29df9ad2401e47cffd9fb51e9ba3 (patch)
treecdf527ff893698ca75b42632dea4d73a9d52cadd /src/libnpass
parentcf70ac8af421dd9f1a53d9e5dbf89b976b02290b (diff)
npass: refactor
https://www.kernel.org/doc/html/v4.10/process/coding-style.html - Function return values and names (-Exxx = failure, 0 = success) for imperative commands (0 = failure, non-zero = success) for predicates
Diffstat (limited to 'src/libnpass')
-rw-r--r--src/libnpass/libnpass.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/libnpass/libnpass.c b/src/libnpass/libnpass.c
index f62f098..779a42a 100644
--- a/src/libnpass/libnpass.c
+++ b/src/libnpass/libnpass.c
@@ -250,6 +250,8 @@ int readstore_all(const char *path, struct store **stor)
err_ret(-errno, "%s", strerror(errno));
}
}
+ if (len == 0)
+ free(*stor);
return (ret < 0) ? ret : len;
}
@@ -309,10 +311,11 @@ int pass_cat(FILE *out, const char *path)
return gpg_decrypt(out, pass_path);
}
-ssize_t pass_getpass(char **lineptr, size_t *n, FILE *stream)
+ssize_t pass_getpass(char **lineptr, FILE *stream)
{
struct termios new, old;
- int ret;
+ size_t len;
+ ssize_t ret;
ret = tcgetattr(fileno(stream), &old);
if (ret < 0)
@@ -324,17 +327,22 @@ ssize_t pass_getpass(char **lineptr, size_t *n, FILE *stream)
if (ret < 0)
err_ret(-errno, "%s", strerror(errno));
- ret = getline(lineptr, n, stream);
- if (ret > 0 && (*lineptr)[ret - 1] == '\n')
- (*lineptr)[ret - 1] = '\0';
- else if (ret < 0)
+ len = 0;
+ *lineptr = NULL;
+ ret = getline(lineptr, &len, stream);
+ if (ret < 0)
err_ret(-errno, "%s", strerror(errno));
+ else if (ret > 0 && (*lineptr)[ret - 1] == '\n')
+ (*lineptr)[--ret] = '\0';
+ len = ret;
ret = tcsetattr(fileno(stream), TCSAFLUSH, &old);
- if (ret < 0)
+ if (ret < 0) {
+ free(*lineptr);
err_ret(-errno, "%s", strerror(errno));
+ }
- return 0;
+ return len;
}
int pass_gen(pass_gen_t gen, char *pass, int len)