1
0
mirror of https://github.com/ericonr/sndio.git synced 2024-02-18 04:45:21 -06:00

simplify conditionals in aucat_mkcookie()

This commit is contained in:
Alexandre Ratchov 2011-04-28 01:31:15 +02:00
parent cc099911f6
commit a583ebc5d9

View File

@ -206,7 +206,7 @@ aucat_wdata(struct aucat *hdl, const void *buf, size_t len, unsigned wbpf, int *
} }
int int
aucat_loadcookie(unsigned char *cookie) aucat_mkcookie(unsigned char *cookie)
{ {
struct stat sb; struct stat sb;
char buf[PATH_MAX], tmp[PATH_MAX], *path; char buf[PATH_MAX], tmp[PATH_MAX], *path;
@ -285,9 +285,10 @@ bad_gen:
#endif #endif
/* /*
* save the cookie, ignore errors * try to save the cookie
*/ */
if (path != NULL) { if (path == NULL)
return 1;
if (strlcpy(tmp, path, PATH_MAX) >= PATH_MAX || if (strlcpy(tmp, path, PATH_MAX) >= PATH_MAX ||
strlcat(tmp, ".XXXXXXXX", PATH_MAX) >= PATH_MAX) { strlcat(tmp, ".XXXXXXXX", PATH_MAX) >= PATH_MAX) {
DPRINTF("%s: too long\n", path); DPRINTF("%s: too long\n", path);
@ -300,13 +301,15 @@ bad_gen:
} }
if (write(fd, cookie, AMSG_COOKIELEN) < 0) { if (write(fd, cookie, AMSG_COOKIELEN) < 0) {
DPERROR(tmp); DPERROR(tmp);
unlink(tmp);
close(fd);
return 1;
} }
close(fd); close(fd);
if (rename(tmp, path) < 0) { if (rename(tmp, path) < 0) {
DPERROR(tmp); DPERROR(tmp);
unlink(tmp); unlink(tmp);
} }
}
return 1; return 1;
} }
@ -449,7 +452,7 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, int isaudio)
*/ */
AMSG_INIT(&hdl->wmsg); AMSG_INIT(&hdl->wmsg);
hdl->wmsg.cmd = AMSG_AUTH; hdl->wmsg.cmd = AMSG_AUTH;
if (!aucat_loadcookie(hdl->wmsg.u.auth.cookie)) if (!aucat_mkcookie(hdl->wmsg.u.auth.cookie))
goto bad_connect; goto bad_connect;
hdl->wtodo = sizeof(struct amsg); hdl->wtodo = sizeof(struct amsg);
if (!aucat_wmsg(hdl, &eof)) if (!aucat_wmsg(hdl, &eof))