diff options
-rw-r--r-- | ftw.c | 2 | ||||
-rw-r--r-- | socket.c | 20 | ||||
-rw-r--r-- | stream.c | 34 | ||||
-rw-r--r-- | sysif.c | 75 | ||||
-rw-r--r-- | sysif.h | 1 | ||||
-rw-r--r-- | termios.c | 15 | ||||
-rw-r--r-- | txr.1 | 2 |
7 files changed, 77 insertions, 72 deletions
@@ -126,7 +126,7 @@ val ftw_wrap(val dirpath, val fn, val flags_in, val nopenfd_in) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("ftw ~a: ~d/~s"), - dirpath, num(eno), string_utf8(strerror(eno)), nao); + dirpath, num(eno), errno_to_str(eno), nao); } default: return num(res); @@ -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); @@ -525,10 +525,8 @@ static void stdio_stream_mark(val stream) val errno_to_string(val err) { - if (err == zero) - return lit("unspecified error"); - else if (is_num(err)) - return string_utf8(strerror(c_num(err))); + if (is_num(err)) + return errno_to_str(c_num(err)); else if (!err) return lit("no error"); else if (err == t) @@ -931,7 +929,7 @@ static val stdio_close(val stream, val throw_on_error) if (result == EOF && throw_on_error) { h->err = num(errno); uw_throwf(file_error_s, lit("error closing ~s: ~d/~s"), - stream, num(errno), string_utf8(strerror(errno)), nao); + stream, num(errno), errno_to_str(errno), nao); } return result != EOF ? t : nil; } @@ -1323,7 +1321,7 @@ static val pipe_close(val stream, val throw_on_error) if (throw_on_error) uw_throwf(process_error_s, lit("unable to obtain status of command ~s: ~d/~s"), - stream, num(errno), string_utf8(strerror(errno)), nao); + stream, num(errno), errno_to_str(errno), nao); } else { #if HAVE_SYS_WAIT if (throw_on_error) { @@ -4066,7 +4064,7 @@ val open_directory(val path) int eno = errno; uw_throwf(errno_to_file_error(eno), lit("error opening directory ~s: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } return make_dir_stream(d); @@ -4081,7 +4079,7 @@ val open_file(val path, val mode_str) if (!f) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("error opening ~s: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } return set_mode_props(m, make_stdio_stream(f, path)); @@ -4096,7 +4094,7 @@ val open_fileno(val fd, val mode_str) int eno = errno; close(c_num(fd)); uw_throwf(errno_to_file_error(eno), lit("error opening descriptor ~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_stdio_stream(f, format(nil, @@ -4116,7 +4114,7 @@ val open_tail(val path, val mode_str, val seek_end_p) if (f && default_null_arg(seek_end_p)) if (fseek(f, 0, SEEK_END) < 0) uw_throwf(file_error_s, lit("error seeking to end of ~s: ~d/~s"), - path, num(errno), string_utf8(strerror(errno)), nao); + path, num(errno), errno_to_str(errno), nao); stream = make_tail_stream(f, path); h = coerce(struct stdio_handle *, stream->co.handle); @@ -4157,7 +4155,7 @@ static int fds_subst(val stream, int fd_std) } uw_throwf(file_error_s, lit("failed to duplicate file descriptor: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); } } @@ -4211,7 +4209,7 @@ val open_command(val path, val mode_str) if (!f) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("error opening pipe ~s: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } uw_unwind { @@ -4262,7 +4260,7 @@ static val open_subprocess(val name, val mode_str, val args, val fun) free(argv); uw_throwf(errno_to_file_error(eno), lit("opening pipe ~s, pipe syscall failed: ~d/~s"), - name, num(eno), string_utf8(strerror(eno)), nao); + name, num(eno), errno_to_str(eno), nao); } if (argv) { @@ -4282,7 +4280,7 @@ static val open_subprocess(val name, val mode_str, val args, val fun) free(argv); } uw_throwf(process_error_s, lit("opening pipe ~s, fork syscall failed: ~d/~s"), - name, num(errno), string_utf8(strerror(errno)), nao); + name, num(errno), errno_to_str(errno), nao); } if (pid == 0) { @@ -4363,7 +4361,7 @@ static val open_subprocess(val name, val mode_str, val args, val fun) ; free(utf8mode); uw_throwf(file_error_s, lit("opening pipe ~s, fdopen failed: ~d/~s"), - name, num(errno), string_utf8(strerror(errno)), nao); + name, num(errno), errno_to_str(errno), nao); } free(utf8mode); @@ -4594,7 +4592,7 @@ static val run(val name, val args) free(argv[i]); free(argv); uw_throwf(process_error_s, lit("opening process ~s, fork syscall failed: ~d/~s"), - name, num(errno), string_utf8(strerror(errno)), nao); + name, num(errno), errno_to_str(errno), nao); } if (pid == 0) { @@ -4644,7 +4642,7 @@ val remove_path(val path, val throw_on_error) if (default_null_arg(throw_on_error) || errno != ENOENT) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("trying to remove ~s: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } return nil; } @@ -4658,7 +4656,7 @@ val rename_path(val from, val to) int eno = errno; uw_throwf(errno_to_file_error(eno), lit("trying to rename ~s to ~s: ~d/~s"), - from, to, num(eno), string_utf8(strerror(eno)), nao); + from, to, num(eno), errno_to_str(eno), nao); } return t; @@ -141,10 +141,8 @@ static val errno_wrap(val newval) return oldval; } -static val strerror_wrap(val errnum) +val errno_to_str(int eno) { - val self = lit("strerror"); - int eno = c_int(errnum, self); #if HAVE_STRERROR_POSIX char buf[128]; return strerror_r(eno, buf, sizeof buf) >= 0 ? string_utf8(buf) : nil; @@ -156,6 +154,13 @@ static val strerror_wrap(val errnum) #endif } +static val strerror_wrap(val errnum) +{ + val self = lit("strerror"); + int eno = c_int(errnum, self); + return errno_to_str(eno); +} + #if HAVE_DAEMON static val daemon_wrap(val nochdir, val noclose) { @@ -294,7 +299,7 @@ static val mkdir_wrap(val path, val mode) if (err < 0) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("mkdir ~a: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } return t; @@ -308,7 +313,7 @@ static val mkdir_wrap(val path, val mode) if (err < 0) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("mkdir ~a: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } return t; @@ -427,7 +432,7 @@ static val ensure_dir(val path, val mode) int eno = c_num(ret); uw_throwf(errno_to_file_error(eno), lit("ensure-dir: ~a: ~d/~s"), path, ret, - string_utf8(strerror(eno)), nao); + errno_to_str(eno), nao); } return ret; @@ -444,7 +449,7 @@ static val chdir_wrap(val path) if (err < 0) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("chdir ~a: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } return t; @@ -462,7 +467,7 @@ val getcwd_wrap(void) free(u8buf); if (eno != ERANGE) { uw_throwf(errno_to_file_error(eno), lit("getcwd: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); } if (2 * guess > guess) guess *= 2; @@ -485,7 +490,7 @@ static val rmdir_wrap(val path) if (err < 0) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("rmdir ~a: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } return t; @@ -526,11 +531,11 @@ static val mknod_wrap(val path, val mode, val dev) #if HAVE_MAKEDEV uw_throwf(errno_to_file_error(eno), lit("mknod ~a ~a ~a (~d:~d): ~d/~s"), path, mode, dev, major_wrap(dev), minor_wrap(dev), num(eno), - string_utf8(strerror(eno)), nao); + errno_to_str(eno), nao); #else uw_throwf(errno_to_file_error(eno), lit("mknod ~a ~a ~a: ~d/~s"), path, mode, dev, num(eno), - string_utf8(strerror(eno)), nao); + errno_to_str(eno), nao); #endif } @@ -552,7 +557,7 @@ static val mkfifo_wrap(val path, val mode) int eno = errno; uw_throwf(errno_to_file_error(eno), lit("mknod ~a ~a: ~d/~s"), path, mode, num(eno), - string_utf8(strerror(eno)), nao); + errno_to_str(eno), nao); } return t; @@ -726,7 +731,7 @@ inval: if (err < 0) { int eno = errno; val error = errno_to_file_error(eno); - val errstr = string_utf8(strerror(eno)); + val errstr = errno_to_str(eno); if (stringp(mode)) uw_throwf(error, lit("~a ~a ~a: ~d/~s"), @@ -762,7 +767,7 @@ static val do_chown(val target, val uid, val gid, val link_p, val self) int eno = errno; uw_throwf(errno_to_file_error(eno), lit("~a ~a ~a ~a: ~d/~s"), self, target, uid, gid, num(eno), - string_utf8(strerror(eno)), nao); + errno_to_str(eno), nao); } return t; @@ -795,7 +800,7 @@ static val symlink_wrap(val target, val to) if (err < 0) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("symlink ~a ~a: ~d/~s"), - target, to, num(eno), string_utf8(strerror(eno)), nao); + target, to, num(eno), errno_to_str(eno), nao); } return t; @@ -814,7 +819,7 @@ static val link_wrap(val target, val to) if (err < 0) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("link ~a ~a: ~d/~s"), - target, to, num(eno), string_utf8(strerror(eno)), nao); + target, to, num(eno), errno_to_str(eno), nao); } return t; @@ -839,7 +844,7 @@ static val readlink_wrap(val path) int eno = errno; free(u8buf); uw_throwf(errno_to_file_error(eno), lit("readlink ~a: ~d/~s"), - path, num(eno), string_utf8(strerror(eno)), nao); + path, num(eno), errno_to_str(eno), nao); } else { val out; u8buf[bytes] = 0; @@ -1004,7 +1009,7 @@ static val close_wrap(val fd, val throw_on_error) if (default_null_arg(throw_on_error)) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("close ~a: ~d/~s"), - fd, num(eno), string_utf8(strerror(eno)), nao); + fd, num(eno), errno_to_str(eno), nao); } return nil; } @@ -1032,7 +1037,7 @@ val exec_wrap(val file, val args_opt) if (execvp(argv[0], argv) < 0) uw_throwf(process_error_s, lit("~s ~a: ~d/~s"), - self, file, num(errno), string_utf8(strerror(errno)), nao); + self, file, num(errno), errno_to_str(errno), nao); uw_throwf(process_error_s, lit("~s ~a returned"), self, file, nao); } @@ -1136,7 +1141,7 @@ static val stat_impl(val obj, int (*statfn)(val, struct stat *), if (res == -1) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("unable to ~a ~a: ~d/~s"), - name, obj, num(eno), string_utf8(strerror(eno)), nao); + name, obj, num(eno), errno_to_str(eno), nao); } return if3(opt_compat && opt_compat <= 113, @@ -1234,7 +1239,7 @@ static val do_utimes(val target, val atime, val atimens, if (res == -1) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("~s: failed: ~d/~s"), - self, num(eno), string_utf8(strerror(eno)), nao); + self, num(eno), errno_to_str(eno), nao); } return t; @@ -1279,7 +1284,7 @@ static val pipe_wrap(void) if (pipe(fd) < 0) { int eno = errno; uw_throwf(errno_to_file_error(eno), lit("pipe failed: ~d/~s"), - num(eno), string_utf8(strerror(eno)), nao); + num(eno), errno_to_str(eno), nao); } return cons(num(fd[0]), num(fd[1])); } @@ -1368,7 +1373,7 @@ static val poll_wrap(val poll_list, val timeout_in) if (res < 0) uw_throwf(file_error_s, lit("poll failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); if (res == 0) return nil; @@ -1436,7 +1441,7 @@ static val getgroups_wrap(void) } uw_throwf(system_error_s, lit("~s failed: ~d/~s"), - self, num(errno), string_utf8(strerror(errno)), nao); + self, num(errno), errno_to_str(errno), nao); abort(); } @@ -1444,7 +1449,7 @@ static val setuid_wrap(val nval) { if (setuid(c_num(nval)) == -1) uw_throwf(system_error_s, lit("setuid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1452,7 +1457,7 @@ static val seteuid_wrap(val nval) { if (seteuid(c_num(nval)) == -1) uw_throwf(system_error_s, lit("seteuid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1460,7 +1465,7 @@ static val setgid_wrap(val nval) { if (setgid(c_num(nval)) == -1) uw_throwf(system_error_s, lit("setgid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1468,7 +1473,7 @@ static val setegid_wrap(val nval) { if (setegid(c_num(nval)) == -1) uw_throwf(system_error_s, lit("setegid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1618,7 +1623,7 @@ static val setgroups_wrap(val list) if (res != 0) uw_throwf(system_error_s, lit("setgroups failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1633,7 +1638,7 @@ static val getresuid_wrap(void) uid_t r, e, s; if (getresuid(&r, &e, &s) != 0) uw_throwf(system_error_s, lit("getresuid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return list(num(r), num(e), num(s), nao); } @@ -1642,7 +1647,7 @@ static val getresgid_wrap(void) gid_t r, e, s; if (getresgid(&r, &e, &s) != 0) uw_throwf(system_error_s, lit("getresgid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return list(num(r), num(e), num(s), nao); } @@ -1650,7 +1655,7 @@ static val setresuid_wrap(val r, val e, val s) { if (setresuid(c_num(r), c_num(e), c_num(s)) != 0) uw_throwf(system_error_s, lit("setresuid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1658,7 +1663,7 @@ static val setresgid_wrap(val r, val e, val s) { if (setresuid(c_num(r), c_num(e), c_num(s)) != 0) uw_throwf(system_error_s, lit("setresuid failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -1920,7 +1925,7 @@ static val crypt_wrap(val wkey, val wsalt) } uw_throwf(error_s, lit("crypt failed: ~d/~s"), num(errno), - string_utf8(strerror(errno)), nao); + errno_to_str(errno), nao); } #endif @@ -2014,7 +2019,7 @@ static val uname_wrap(void) return out; } uw_throwf(error_s, lit("uname failed: ~d/~s"), num(errno), - string_utf8(strerror(errno)), nao); + errno_to_str(errno), nao); } #endif @@ -37,6 +37,7 @@ extern val path_s; val errno_to_file_error(int err); val getenv_wrap(val name); +val errno_to_str(int err); val at_exit_call(val func); val at_exit_do_not_call(val func); val usleep_wrap(val usec); @@ -44,6 +44,7 @@ #include "unwind.h" #include "stream.h" #include "struct.h" +#include "sysif.h" #include "termios.h" val termios_s, iflag_s, oflag_s, cflag_s, lflag_s, cc_s, ispeed_s, ospeed_s; @@ -256,7 +257,7 @@ static val tcgetattr_wrap(val stream) if (res < 0) uw_throwf(system_error_s, lit("tcgetattr failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return termios_unpack(&tio); } @@ -273,7 +274,7 @@ static val tcsetattr_wrap(val termios, val actions, val stream) if (res < 0) uw_throwf(system_error_s, lit("tcgetattr failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); termios_pack(&tio, termios); @@ -281,7 +282,7 @@ static val tcsetattr_wrap(val termios, val actions, val stream) if (res < 0) uw_throwf(system_error_s, lit("tcsetattr failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return termios; } @@ -294,7 +295,7 @@ static val tcsendbreak_wrap(val duration, val stream) if (res < 0) uw_throwf(system_error_s, lit("tcsendbreak failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -306,7 +307,7 @@ static val tcdrain_wrap(val stream) if (res < 0) uw_throwf(system_error_s, lit("tcdrain failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -318,7 +319,7 @@ static val tcflush_wrap(val queue, val stream) if (res < 0) uw_throwf(system_error_s, lit("tcflush failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -330,7 +331,7 @@ static val tcflow_wrap(val action, val stream) if (res < 0) uw_throwf(system_error_s, lit("tcflow failed: ~d/~s"), - num(errno), string_utf8(strerror(errno)), nao); + num(errno), errno_to_str(errno), nao); return t; } @@ -58598,7 +58598,7 @@ obtained from the .code errno function. -If the host platform fails to provide a descripion, the function returns +If the host platform fails to provide a description, the function returns .codn nil . .coNP Function @ exit |