From f61bf72e61f012e173acc15dfda71a3e5371bde1 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 19 Jun 2020 20:55:26 -0700 Subject: Replace all strerror calls with wrapper. All string_utf8(strerror(x)) calls are replaced with errno_to_str(x). * sysif.c (errno_to_str): New function. (strerror_wrap): Now implemented via call to errno_to_str. (mkdir_wrap, ensure_dir, chdir_wrap, getcwd_wrap, rmdir_wrap, mknod_wrap, mkfifo_wrap, chmod_wrap, do_chown, symlink_wrap, link_wrap, readlink_wrap, close_wrap, exec_wrap, stat_impl, do_utimes, pipe_wrap, poll_wrap, getgroups_wrap, setuid_wrap, seteuid_wrap, setgid_wrap, setegid_wrap, setgroups_wrap, getresuid_wrap, getresgid_wrap, setresuid_wrap, setresgid_wrap, crypt_wrap, uname_wrap): Use errno_to_str. * sysif.h (errno_to_str): Declared. * ftw.c (ftw_wrap): Use errno_to_str. * socket.c (dgram_get_byte_callback, dgram_flush, sock_bind, open_sockfd, sock_connect, sock_listen, sock_accept, sock_shutdown, sock_timeout, socketpair_wrap): Likewise. * stream.c (errno_to_string): Likewise, and don't handle zero case any more; pass down to errno_to_str. (stdio_close, pipe_close open_directory, open_file, open_fileno, open_tail, fds_subst, open_command, open_subprocess, run, remove_path, rename_path): Use errno_to_str. * termios.c (tcgetattr_wrap, tcsetattr_wrap, tcsetattr_wrap, tcsendbreak_wrap, tcdrain_wrap, tcflush_wrap, tcflow_wrap): Likewise. diff --git a/termios.c b/termios.c --- socket.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'socket.c') diff --git a/socket.c b/socket.c index 9b213e4f..f0c252bf 100644 --- a/socket.c +++ b/socket.c @@ -427,7 +427,7 @@ static int dgram_get_byte_callback(mem_t *ctx) d->err = errno; uw_throwf(socket_error_s, lit("get-byte: recv on ~s failed: ~d/~s"), - d->stream, num(errno), string_utf8(strerror(errno)), nao); + d->stream, num(errno), errno_to_str(errno), nao); } uw_unwind { @@ -516,7 +516,7 @@ static val dgram_flush(val stream) lit("flush-stream: sendto on ~s ~a: ~d/~s"), stream, (nwrit < 0) ? lit("failed") : lit("truncated"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); } free(d->tx_buf); @@ -692,7 +692,7 @@ static val sock_bind(val sock, val sockaddr) if (bind(fd, coerce(struct sockaddr *, &sa), salen) != 0) uw_throwf(socket_error_s, lit("sock-bind failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); stream_set_prop(sock, addr_k, sockaddr); return t; @@ -819,7 +819,7 @@ static val open_sockfd(val fd, val family, val type, val mode_str) int eno = errno; close(c_num(fd)); uw_throwf(errno_to_file_error(eno), lit("error creating stream for socket ~a: ~d/~s"), - fd, num(eno), string_utf8(strerror(eno)), nao); + fd, num(eno), errno_to_str(eno), nao); } return set_mode_props(m, make_sock_stream(f, family, type)); @@ -841,7 +841,7 @@ static val sock_connect(val sock, val sockaddr, val timeout) if (to_connect(c_num(sfd), coerce(struct sockaddr *, &sa), salen, sock, sockaddr, default_null_arg(timeout)) != 0) uw_throwf(socket_error_s, lit("sock-connect ~s to addr ~s: ~d/~s"), - sock, sockaddr, num(errno), string_utf8(strerror(errno)), nao); + sock, sockaddr, num(errno), errno_to_str(errno), nao); sock_set_peer(sock, sockaddr); @@ -901,7 +901,7 @@ static val sock_listen(val sock, val backlog) return t; failed: uw_throwf(socket_error_s, lit("sock-listen failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); } static val sock_accept(val sock, val mode_str, val timeout_in) @@ -1012,7 +1012,7 @@ static val sock_accept(val sock, val mode_str, val timeout_in) } failed: uw_throwf(socket_error_s, lit("accept failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); badfd: uw_throwf(socket_error_s, lit("sock-accept: cannot accept on ~s"), sock, nao); @@ -1026,7 +1026,7 @@ static val sock_shutdown(val sock, val how) if (shutdown(c_num(sfd), c_num(default_arg(how, num_fast(SHUT_WR))))) uw_throwf(socket_error_s, lit("shutdown failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1044,7 +1044,7 @@ static val sock_timeout(val sock, val usec, val name, int which) if (setsockopt(fd, SOL_SOCKET, which, &tv, sizeof tv) != 0) uw_throwf(socket_error_s, lit("~a failed on ~s: ~d/~s"), name, sock, num(errno), - string_utf8(strerror(errno)), nao); + errno_to_str(errno), nao); return sock; } @@ -1076,7 +1076,7 @@ static val socketpair_wrap(val family, val type, val mode_str) if (res < 0) uw_throwf(socket_error_s, lit("sock-pair failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); { val s0 = open_sockfd(num(sv[0]), family, type, mode_str); -- cgit v1.2.3