safe

Password protected secret keeper
git clone git://git.z3bra.org/safe.git
Log | Files | Refs | README | LICENSE

commit cd4ed5d1df38d2a509dbfea3265ac7e949deb2b9
parent 32c829dd0d53fdfdb9427e11e82c79399080e320
Author: Willy Goiffon <dev@z3bra.org>
Date:   Mon, 24 Jun 2019 15:54:07 +0200

Simplify readkey() error handling

Diffstat:
safe.c | 19++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/safe.c b/safe.c @@ -193,23 +193,20 @@ readkey(struct safe *s, char *path) return -1; if (connect(sfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) - return -1; - - if ((n = xread(sfd, s->salt, sizeof(s->salt), NULL)) < 0) - return -1; + goto err; - if (!n) { - errno = ENOKEY; - close(sfd); - return -1; - } + if ((n = xread(sfd, s->salt, sizeof(s->salt), NULL)) <= 0) + goto err; if (xread(sfd, s->key, sizeof(s->key), NULL) < 0) - return -1; + goto err; close(sfd); - return 0; + +err: + close(sfd); + return -1; } int