More try implementation progress.

This commit is contained in:
2026-06-27 18:58:20 -05:00
parent 7a4ad7162a
commit c6342f739a
+257 -24
View File
@@ -135,7 +135,21 @@ ci2_try_getsockname(int sockfd,
}
int
ci2_try_getsockopt(int, int, int, void* restrict, socklen_t* restrict);
ci2_try_getsockopt(int sockfd,
int level,
int optname,
void* restrict optval,
socklen_t* restrict optlen)
{
int res = getsockopt(sockfd, level, optname, optval, optlen);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_listen(int sockfd, int backlog)
@@ -239,7 +253,21 @@ ci2_try_sendto(int sockfd,
}
int
ci2_try_setsockopt(int, int, int, const void*, socklen_t);
ci2_try_setsockopt(int sockfd,
int level,
int optname,
const void* optval,
socklen_t optlen)
{
int res = setsockopt(sockfd, level, optname, optval, optlen);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_shutdown(int fd, int how)
@@ -255,7 +283,17 @@ ci2_try_shutdown(int fd, int how)
}
int
ci2_try_sockatmark(int);
ci2_try_sockatmark(int sockfd)
{
int res = sockatmark(sockfd);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_socket(int domain, int type, int protocol)
@@ -271,30 +309,103 @@ ci2_try_socket(int domain, int type, int protocol)
}
int
ci2_try_socketpair(int, int, int, int[2]);
ci2_try_socketpair(int domain, int type, int protocol, int sv[2])
{
int res = socketpair(domain, type, protocol, sv);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
/* sys/stat.h */
int
ci2_try_chmod(const char*, mode_t);
ci2_try_chmod(const char* path, mode_t mode)
{
int res = chmod(path, mode);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_fchmod(int, mode_t);
ci2_try_fchmod(int fd, mode_t mode)
{
int res = fchmod(fd, mode);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_fchmodat(int, const char*, mode_t, int);
ci2_try_fchmodat(int dirfd, const char* path, mode_t mode, int flags)
{
int res = fchmodat(dirfd, path, mode, flags);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_fstat(int, struct stat*);
ci2_try_fstat(int fd, struct stat* buf)
{
int res = fstat(fd, buf);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_fstatat(int, const char* restrict, struct stat* restrict, int);
ci2_try_fstatat(int fd,
const char* restrict path,
struct stat* restrict buf,
int flag)
{
int res = fstatat(fd, path, buf, flag);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_futimens(int, const struct timespec[2]);
int
ci2_try_lstat(const char* restrict, struct stat* restrict);
ci2_try_lstat(const char* restrict path, struct stat* restrict buf)
{
int res = lstat(path, buf);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_mkdir(const char*, mode_t);
@@ -303,10 +414,30 @@ int
ci2_try_mkdirat(int, const char*, mode_t);
int
ci2_try_mkfifo(const char*, mode_t);
ci2_try_mkfifo(const char* path, mode_t mode)
{
int res = mkfifo(path, mode);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_mkfifoat(int, const char*, mode_t);
ci2_try_mkfifoat(int dirfd, const char* path, mode_t mode)
{
int res = mkfifoat(dirfd, path, mode);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_mknod(const char*, mode_t, dev_t);
@@ -561,13 +692,43 @@ ci2_try_pipe(int fds[2])
}
ssize_t
ci2_try_pread(int, void*, size_t, off_t);
ci2_try_pread(int fd, void* buf, size_t len, off_t off)
{
ssize_t res = pread(fd, buf, len, off);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
ssize_t
ci2_try_pwrite(int, const void*, size_t, off_t);
ci2_try_pwrite(int fd, const void* buf, size_t len, off_t off)
{
ssize_t res = pwrite(fd, buf, len, off);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
ssize_t
ci2_try_read(int, void*, size_t);
ci2_try_read(int fd, void* buf, size_t len)
{
ssize_t res = read(fd, buf, len);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
ssize_t
ci2_try_readlink(const char* restrict, char* restrict, size_t);
@@ -638,11 +799,24 @@ int
ci2_try_unlinkat(int, const char*, int);
ssize_t
ci2_try_write(int, const void*, size_t);
ci2_try_write(int fd, const void* buf, size_t len)
{
ssize_t res = write(fd, buf, len);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
/* stdio.h */
void
ci2_try_clearerr(FILE*);
ci2_try_clearerr(FILE* fp)
{ // shouldn't fail.
clearerr(fp);
}
char*
ci2_try_ctermid(char*);
@@ -677,13 +851,29 @@ ci2_try_fdopen(int fd, const char* mode)
}
int
ci2_try_feof(FILE*);
ci2_try_feof(FILE* fp)
{ // shouldn't fail
return feof(fp);
}
int
ci2_try_ferror(FILE*);
ci2_try_ferror(FILE* fp)
{ // shouldn't fail
return ferror(fp);
}
int
ci2_try_fflush(FILE*);
ci2_try_fflush(FILE* fp)
{
int res = fflush(fp);
if (res != 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_fgetc(FILE*);
@@ -720,13 +910,43 @@ int
ci2_try_fprintf(FILE* restrict, const char* restrict, ...);
int
ci2_try_fputc(int, FILE*);
ci2_try_fputc(int c, FILE* fp)
{
int res = fputc(c, fp);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_fputs(const char* restrict, FILE* restrict);
ci2_try_fputs(const char* restrict s, FILE* restrict fp)
{
int res = fputs(s, fp);
if (res < 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
size_t
ci2_try_fread(void* restrict, size_t, size_t, FILE* restrict);
ci2_try_fread(void* restrict buf, size_t size, size_t count, FILE* restrict fp)
{
size_t res = fread(buf, size, count, fp);
if (res == 0 && ferror(fp)) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
FILE*
ci2_try_freopen(const char* restrict path,
@@ -768,7 +988,20 @@ void
ci2_try_funlockfile(FILE*);
size_t
ci2_try_fwrite(const void* restrict, size_t, size_t, FILE* restrict);
ci2_try_fwrite(const void* restrict buf,
size_t size,
size_t count,
FILE* restrict fp)
{
size_t res = fwrite(buf, size, count, fp);
if (res == 0) {
int err = errno;
char* err_str = strerror(err);
struct Exception e = { err_str };
CI2_RAISE(e);
}
return res;
}
int
ci2_try_getc(FILE*);