From ae29e4a72dd7fea1915f6266a2402e53987ebc1d Mon Sep 17 00:00:00 2001 From: Randy Jordan Date: Thu, 25 Jun 2026 20:42:52 -0500 Subject: [PATCH] ci2_try interface and implementation skeleton --- README.md | 2 + include/ci2.h | 1 + include/platform/mem/ci2_mem.h | 2 +- include/platform/try/ci2_try.h | 807 +++++++++++++++++++++++++++++++++ src/ci2_try.c | 798 ++++++++++++++++++++++++++++++++ 5 files changed, 1609 insertions(+), 1 deletion(-) create mode 100644 include/platform/try/ci2_try.h create mode 100644 src/ci2_try.c diff --git a/README.md b/README.md index 200cccc..d036b8d 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Inspired by all in the acknowledgments, this is my own personal C codebase. ## Features ## Todos +- [ ] ci2_try Implementations, parameter naming, and comments. + ## Usage diff --git a/include/ci2.h b/include/ci2.h index 14a63fe..fc4262d 100644 --- a/include/ci2.h +++ b/include/ci2.h @@ -33,5 +33,6 @@ You get to decide which parts of that platform layer you'd like to use. /* Then you import which parts of the platform layer, you'd like. */ #include "./platform/error/ci2_exception.h" #include "./platform/mem/ci2_mem.h" +#include "./platform/try/ci2_try.h" #endif // ci2.h diff --git a/include/platform/mem/ci2_mem.h b/include/platform/mem/ci2_mem.h index 0c4c78f..46fc4cb 100644 --- a/include/platform/mem/ci2_mem.h +++ b/include/platform/mem/ci2_mem.h @@ -29,7 +29,7 @@ a robust way to handle errors. #ifndef CI2_MEM_H #define CI2_MEM_H -#include "../ci2_platform.h" // Exceptions +#include "../ci2_platform.h" // platform layer #include "../error/ci2_exception.h" // Exceptions #include // size_t diff --git a/include/platform/try/ci2_try.h b/include/platform/try/ci2_try.h new file mode 100644 index 0000000..79a7310 --- /dev/null +++ b/include/platform/try/ci2_try.h @@ -0,0 +1,807 @@ +/* - | Copyright / About | ---------------------------------------------------- + Copyright (c) 2026 Randy Jordan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +This is the ci2_try.h interface. The functions all are just wrappers for the +general c libraries. If they fail they raise an exception with macro magic. All +other functions that may raise an exception are in include/platform/mem. It's +not recommended to use these functions, as they are hard to debug and it's not +a robust way to handle errors. + * --------------------------------------------------------------------------*/ +#ifndef CI2_TRY_H +#define CI2_TRY_H + +#include "../ci2_platform.h" +#include +#include +#include +#include + +#include +#include + +/* fcntl.h */ +CI2_DEF int +ci2_try_creat(const char* path, mode_t mode); + +CI2_DEF int +ci2_try_fcntl(int fd, int cmd, long args); + +CI2_DEF int +ci2_try_open(const char* pathname, int flags, mode_t mode); + +/* socket.h */ +CI2_DEF int +ci2_try_accept(int, struct sockaddr* restrict, socklen_t* restrict); + +CI2_DEF int +ci2_try_bind(int, const struct sockaddr*, socklen_t); + +CI2_DEF int +ci2_try_connect(int, const struct sockaddr*, socklen_t); + +CI2_DEF int +ci2_try_getpeername(int, struct sockaddr* restrict, socklen_t* restrict); + +CI2_DEF int +ci2_try_getsockname(int, struct sockaddr* restrict, socklen_t* restrict); + +CI2_DEF int +ci2_try_getsockopt(int, int, int, void* restrict, socklen_t* restrict); + +CI2_DEF int +ci2_try_listen(int, int); + +CI2_DEF ssize_t +ci2_try_recv(int, void*, size_t, int); + +CI2_DEF ssize_t +ci2_try_recvfrom(int, + void* restrict, + size_t, + int, + struct sockaddr* restrict, + socklen_t* restrict); + +CI2_DEF ssize_t +ci2_try_recvmsg(int, struct msghdr*, int); + +CI2_DEF ssize_t +ci2_try_send(int, const void*, size_t, int); + +CI2_DEF ssize_t +ci2_try_sendmsg(int, const struct msghdr*, int); + +CI2_DEF ssize_t +ci2_try_sendto(int, + const void*, + size_t, + int, + const struct sockaddr*, + socklen_t); + +CI2_DEF int +ci2_try_setsockopt(int, int, int, const void*, socklen_t); + +CI2_DEF int +ci2_try_shutdown(int, int); + +CI2_DEF int +ci2_try_sockatmark(int); + +CI2_DEF int +ci2_try_socket(int, int, int); + +CI2_DEF int +ci2_try_socketpair(int, int, int, int[2]); + +/* sys/stat.h */ + +CI2_DEF int +ci2_try_chmod(const char*, mode_t); + +CI2_DEF int +ci2_try_fchmod(int, mode_t); + +CI2_DEF int +ci2_try_fchmodat(int, const char*, mode_t, int); + +CI2_DEF int +ci2_try_fstat(int, struct stat*); + +CI2_DEF int +ci2_try_fstatat(int, const char* restrict, struct stat* restrict, int); + +CI2_DEF int +ci2_try_futimens(int, const struct timespec[2]); + +CI2_DEF int +ci2_try_lstat(const char* restrict, struct stat* restrict); + +CI2_DEF int +ci2_try_mkdir(const char*, mode_t); + +CI2_DEF int +ci2_try_mkdirat(int, const char*, mode_t); + +CI2_DEF int +ci2_try_mkfifo(const char*, mode_t); + +CI2_DEF int +ci2_try_mkfifoat(int, const char*, mode_t); + +CI2_DEF int +ci2_try_mknod(const char*, mode_t, dev_t); + +CI2_DEF int +ci2_try_mknodat(int, const char*, mode_t, dev_t); + +CI2_DEF int +ci2_try_stat(const char* restrict, struct stat* restrict); + +CI2_DEF mode_t ci2_try_umask(mode_t); + +CI2_DEF int +ci2_try_utimensat(int, const char*, const struct timespec[2], int); + +/* unistd.h */ +CI2_DEF int +ci2_try_access(const char*, int); + +CI2_DEF unsigned +ci2_try_alarm(unsigned); + +CI2_DEF int +ci2_try_chdir(const char*); + +CI2_DEF int +ci2_try_chown(const char*, uid_t, gid_t); + +CI2_DEF int +ci2_try_close(int); + +CI2_DEF size_t +ci2_try_confstr(int, char*, size_t); + +CI2_DEF char* +ci2_try_crypt(const char*, const char*); + +CI2_DEF int +ci2_try_dup(int); + +CI2_DEF int +ci2_try_dup2(int, int); + +CI2_DEF void +ci2_try_exit(int); + +CI2_DEF void +ci2_try_encrypt(char[64], int); + +CI2_DEF int +ci2_try_execl(const char*, const char*, ...); + +CI2_DEF int +ci2_try_execle(const char*, const char*, ...); + +CI2_DEF int +ci2_try_execlp(const char*, const char*, ...); + +CI2_DEF int +ci2_try_execv(const char*, char* const[]); + +CI2_DEF int +ci2_try_execve(const char*, char* const[], char* const[]); + +CI2_DEF int +ci2_try_execvp(const char*, char* const[]); + +CI2_DEF int +ci2_try_faccessat(int, const char*, int, int); + +CI2_DEF int +ci2_try_fchdir(int); + +CI2_DEF int +ci2_try_fchown(int, uid_t, gid_t); + +CI2_DEF int +ci2_try_fchownat(int, const char*, uid_t, gid_t, int); + +CI2_DEF int +ci2_try_fdatasync(int); + +CI2_DEF int +ci2_try_fexecve(int, char* const[], char* const[]); + +CI2_DEF pid_t +ci2_try_fork(void); + +CI2_DEF long +ci2_try_fpathconf(int, int); + +CI2_DEF int +ci2_try_fsync(int); + +CI2_DEF int +ci2_try_ftruncate(int, off_t); + +CI2_DEF char* +ci2_try_getcwd(char*, size_t); + +CI2_DEF gid_t +ci2_try_getegid(void); + +CI2_DEF uid_t +ci2_try_geteuid(void); + +CI2_DEF gid_t +ci2_try_getgid(void); + +CI2_DEF int +ci2_try_getgroups(int, gid_t[]); + +CI2_DEF long +ci2_try_gethostid(void); + +CI2_DEF int +ci2_try_gethostname(char*, size_t); + +CI2_DEF char* +ci2_try_getlogin(void); + +CI2_DEF int +ci2_try_getlogin_r(char*, size_t); + +CI2_DEF int +ci2_try_getopt(int, char* const[], const char*); + +CI2_DEF pid_t ci2_try_getpgid(pid_t); + +CI2_DEF pid_t +ci2_try_getpgrp(void); + +CI2_DEF pid_t +ci2_try_getpid(void); + +CI2_DEF pid_t +ci2_try_getppid(void); + +CI2_DEF pid_t ci2_try_getsid(pid_t); + +CI2_DEF uid_t +ci2_try_getuid(void); + +CI2_DEF int +ci2_try_isatty(int); + +CI2_DEF int +ci2_try_lchown(const char*, uid_t, gid_t); + +CI2_DEF int +ci2_try_link(const char*, const char*); + +CI2_DEF int +ci2_try_linkat(int, const char*, int, const char*, int); + +CI2_DEF int +ci2_try_lockf(int, int, off_t); + +CI2_DEF off_t +ci2_try_lseek(int, off_t, int); + +CI2_DEF int +ci2_try_nice(int); + +CI2_DEF long +ci2_try_pathconf(const char*, int); + +CI2_DEF int +ci2_try_pause(void); + +CI2_DEF int +ci2_try_pipe(int[2]); + +CI2_DEF ssize_t +ci2_try_pread(int, void*, size_t, off_t); + +CI2_DEF ssize_t +ci2_try_pwrite(int, const void*, size_t, off_t); + +CI2_DEF ssize_t +ci2_try_read(int, void*, size_t); + +CI2_DEF ssize_t +ci2_try_readlink(const char* restrict, char* restrict, size_t); + +CI2_DEF ssize_t +ci2_try_readlinkat(int, const char* restrict, char* restrict, size_t); + +CI2_DEF int +ci2_try_rmdir(const char*); + +CI2_DEF int ci2_try_setegid(gid_t); + +CI2_DEF int ci2_try_seteuid(uid_t); + +CI2_DEF int ci2_try_setgid(gid_t); + +CI2_DEF int ci2_try_setpgid(pid_t, pid_t); + +CI2_DEF pid_t +ci2_try_setpgrp(void); + +CI2_DEF int ci2_try_setregid(gid_t, gid_t); + +CI2_DEF int ci2_try_setreuid(uid_t, uid_t); + +CI2_DEF pid_t +ci2_try_setsid(void); + +CI2_DEF int ci2_try_setuid(uid_t); + +CI2_DEF unsigned +ci2_try_sleep(unsigned); + +CI2_DEF void +ci2_try_swab(const void* restrict, void* restrict, ssize_t); + +CI2_DEF int +ci2_try_symlink(const char*, const char*); + +CI2_DEF int +ci2_try_symlinkat(const char*, int, const char*); + +CI2_DEF void +ci2_try_sync(void); + +CI2_DEF long +ci2_try_sysconf(int); + +CI2_DEF pid_t +ci2_try_tcgetpgrp(int); + +CI2_DEF int +ci2_try_tcsetpgrp(int, pid_t); + +CI2_DEF int +ci2_try_truncate(const char*, off_t); + +CI2_DEF char* +ci2_try_ttyname(int); + +CI2_DEF int +ci2_try_ttyname_r(int, char*, size_t); + +CI2_DEF int +ci2_try_unlink(const char*); + +CI2_DEF int +ci2_try_unlinkat(int, const char*, int); + +CI2_DEF ssize_t +ci2_try_write(int, const void*, size_t); + +/* stdio.h */ +CI2_DEF void +ci2_try_clearerr(FILE*); + +CI2_DEF char* +ci2_try_ctermid(char*); + +CI2_DEF int +ci2_try_dprintf(int, const char* restrict, ...); + +CI2_DEF int +ci2_try_fclose(FILE*); + +CI2_DEF FILE* +ci2_try_fdopen(int, const char*); + +CI2_DEF int +ci2_try_feof(FILE*); + +CI2_DEF int +ci2_try_ferror(FILE*); + +CI2_DEF int +ci2_try_fflush(FILE*); + +CI2_DEF int +ci2_try_fgetc(FILE*); + +CI2_DEF int +ci2_try_fgetpos(FILE* restrict, fpos_t* restrict); + +CI2_DEF char* +ci2_try_fgets(char* restrict, int, FILE* restrict); + +CI2_DEF int +ci2_try_fileno(FILE*); + +CI2_DEF void +ci2_try_flockfile(FILE*); + +CI2_DEF FILE* +ci2_try_fmemopen(void* restrict, size_t, const char* restrict); + +CI2_DEF FILE* +ci2_try_fopen(const char* restrict, const char* restrict); + +CI2_DEF int +ci2_try_fprintf(FILE* restrict, const char* restrict, ...); + +CI2_DEF int +ci2_try_fputc(int, FILE*); + +CI2_DEF int +ci2_try_fputs(const char* restrict, FILE* restrict); + +CI2_DEF size_t +ci2_try_fread(void* restrict, size_t, size_t, FILE* restrict); + +CI2_DEF FILE* +ci2_try_freopen(const char* restrict, const char* restrict, FILE* restrict); + +CI2_DEF int +ci2_try_fscanf(FILE* restrict, const char* restrict, ...); + +CI2_DEF int +ci2_try_fseek(FILE*, long, int); + +CI2_DEF int +ci2_try_fseeko(FILE*, off_t, int); + +CI2_DEF int +ci2_try_fsetpos(FILE*, const fpos_t*); + +CI2_DEF long +ci2_try_ftell(FILE*); + +CI2_DEF off_t +ci2_try_ftello(FILE*); + +CI2_DEF int +ci2_try_ftrylockfile(FILE*); + +CI2_DEF void +ci2_try_funlockfile(FILE*); + +CI2_DEF size_t +ci2_try_fwrite(const void* restrict, size_t, size_t, FILE* restrict); + +CI2_DEF int +ci2_try_getc(FILE*); + +CI2_DEF int +ci2_try_getchar(void); + +CI2_DEF int +ci2_try_getc_unlocked(FILE*); + +CI2_DEF int +ci2_try_getchar_unlocked(void); + +CI2_DEF ssize_t +ci2_try_getdelim(char** restrict, size_t* restrict, int, FILE* restrict); + +CI2_DEF ssize_t +ci2_try_getline(char** restrict, size_t* restrict, FILE* restrict); + +CI2_DEF char* +ci2_try_gets(char*); + +CI2_DEF FILE* +ci2_try_open_memstream(char**, size_t*); + +CI2_DEF int +ci2_try_pclose(FILE*); + +CI2_DEF void +ci2_try_perror(const char*); + +CI2_DEF FILE* +ci2_try_popen(const char*, const char*); + +CI2_DEF int +ci2_try_printf(const char* restrict, ...); + +CI2_DEF int +ci2_try_putc(int, FILE*); + +CI2_DEF int +ci2_try_putchar(int); + +CI2_DEF int +ci2_try_putc_unlocked(int, FILE*); + +CI2_DEF int +ci2_try_putchar_unlocked(int); + +CI2_DEF int +ci2_try_puts(const char*); + +CI2_DEF int +ci2_try_remove(const char*); + +CI2_DEF int +ci2_try_rename(const char*, const char*); + +CI2_DEF int +ci2_try_renameat(int, const char*, int, const char*); + +CI2_DEF void +ci2_try_rewind(FILE*); + +CI2_DEF int +ci2_try_scanf(const char* restrict, ...); + +CI2_DEF void +ci2_try_setbuf(FILE* restrict, char* restrict); + +CI2_DEF int +ci2_try_setvbuf(FILE* restrict, char* restrict, int, size_t); + +CI2_DEF int +ci2_try_snprintf(char* restrict, size_t, const char* restrict, ...); + +CI2_DEF int +ci2_try_sprintf(char* restrict, const char* restrict, ...); + +CI2_DEF int +ci2_try_sscanf(const char* restrict, const char* restrict, ...); + +CI2_DEF char* +ci2_try_tempnam(const char*, const char*); + +CI2_DEF FILE* +ci2_try_tmpfile(void); + +CI2_DEF char* +ci2_try_tmpnam(char*); + +CI2_DEF int +ci2_try_ungetc(int, FILE*); + +CI2_DEF int +ci2_try_vdprintf(int, const char* restrict, va_list); + +CI2_DEF int +ci2_try_vfprintf(FILE* restrict, const char* restrict, va_list); + +CI2_DEF int +ci2_try_vfscanf(FILE* restrict, const char* restrict, va_list); + +CI2_DEF int +ci2_try_vprintf(const char* restrict, va_list); + +CI2_DEF int +ci2_try_vscanf(const char* restrict, va_list); + +CI2_DEF int +ci2_try_vsnprintf(char* restrict, size_t, const char* restrict, va_list); + +CI2_DEF int +ci2_try_vsprintf(char* restrict, const char* restrict, va_list); + +CI2_DEF int +ci2_try_vsscanf(const char* restrict, const char* restrict, va_list); + +/* stdlib.h */ +CI2_DEF void +ci2_try_Exit(int); + +CI2_DEF long +ci2_try_a64l(const char*); + +CI2_DEF void +ci2_try_abort(void); + +CI2_DEF int +ci2_try_abs(int); + +CI2_DEF int +ci2_try_atexit(void (*)(void)); + +CI2_DEF double +ci2_try_atof(const char*); + +CI2_DEF int +ci2_try_atoi(const char*); + +CI2_DEF long +ci2_try_atol(const char*); + +CI2_DEF long long +ci2_try_atoll(const char*); + +CI2_DEF void* +ci2_try_bsearch(const void*, + const void*, + size_t, + size_t, + int (*)(const void*, const void*)); + +CI2_DEF void* +ci2_try_calloc(size_t, size_t); + +CI2_DEF div_t +ci2_try_div(int, int); + +CI2_DEF double +ci2_try_drand48(void); + +CI2_DEF double +ci2_try_erand48(unsigned short[3]); + +CI2_DEF void +ci2_try_exit(int); + +CI2_DEF void +ci2_try_free(void*); + +CI2_DEF char* +ci2_try_getenv(const char*); + +CI2_DEF int +ci2_try_getsubopt(char**, char* const*, char**); + +CI2_DEF int +ci2_try_grantpt(int); + +CI2_DEF char* +ci2_try_initstate(unsigned, char*, size_t); + +CI2_DEF long +ci2_try_jrand48(unsigned short[3]); + +CI2_DEF char* +ci2_try_l64a(long); + +CI2_DEF long +ci2_try_labs(long); + +CI2_DEF void +ci2_try_lcong48(unsigned short[7]); + +CI2_DEF ldiv_t +ci2_try_ldiv(long, long); + +CI2_DEF long long +ci2_try_llabs(long long); + +CI2_DEF lldiv_t +ci2_try_lldiv(long long, long long); + +CI2_DEF long +ci2_try_lrand48(void); + +CI2_DEF void* +ci2_try_malloc(size_t); + +CI2_DEF int +ci2_try_mblen(const char*, size_t); + +CI2_DEF size_t +ci2_try_mbstowcs(wchar_t* restrict, const char* restrict, size_t); + +CI2_DEF int +ci2_try_mbtowc(wchar_t* restrict, const char* restrict, size_t); + +CI2_DEF char* +ci2_try_mkdtemp(char*); + +CI2_DEF int +ci2_try_mkstemp(char*); + +CI2_DEF long +ci2_try_mrand48(void); + +CI2_DEF long +ci2_try_nrand48(unsigned short[3]); + +CI2_DEF int +ci2_try_posix_memalign(void**, size_t, size_t); + +CI2_DEF int +ci2_try_posix_openpt(int); + +CI2_DEF char* +ci2_try_ptsname(int); + +CI2_DEF int +ci2_try_putenv(char*); + +CI2_DEF void +ci2_try_qsort(void*, size_t, size_t, int (*)(const void*, const void*)); + +CI2_DEF int +ci2_try_rand(void); + +CI2_DEF int +ci2_try_rand_r(unsigned*); + +CI2_DEF long +ci2_try_random(void); + +CI2_DEF void* +ci2_try_realloc(void*, size_t); + +CI2_DEF char* +ci2_try_realpath(const char* restrict, char* restrict); + +CI2_DEF unsigned short* +ci2_try_seed48(unsigned short[3]); + +CI2_DEF int +ci2_try_setenv(const char*, const char*, int); + +CI2_DEF void +ci2_try_setkey(const char*); + +CI2_DEF char* +ci2_try_setstate(char*); + +CI2_DEF void +ci2_try_srand(unsigned); + +CI2_DEF void +ci2_try_srand48(long); + +CI2_DEF void +ci2_try_srandom(unsigned); + +CI2_DEF double +ci2_try_strtod(const char* restrict, char** restrict); + +CI2_DEF float +ci2_try_strtof(const char* restrict, char** restrict); + +CI2_DEF long +ci2_try_strtol(const char* restrict, char** restrict, int); + +CI2_DEF long double +ci2_try_strtold(const char* restrict, char** restrict); + +CI2_DEF long long +ci2_try_strtoll(const char* restrict, char** restrict, int); + +CI2_DEF unsigned long +ci2_try_strtoul(const char* restrict, char** restrict, int); + +CI2_DEF unsigned long long +ci2_try_strtoull(const char* restrict, char** restrict, int); + +CI2_DEF int +ci2_try_system(const char*); + +CI2_DEF int +ci2_try_unlockpt(int); + +CI2_DEF int +ci2_try_unsetenv(const char*); + +CI2_DEF size_t +ci2_try_wcstombs(char* restrict, const wchar_t* restrict, size_t); + +CI2_DEF int +ci2_try_wctomb(char*, wchar_t); + +#endif // ci2_try.h diff --git a/src/ci2_try.c b/src/ci2_try.c new file mode 100644 index 0000000..176373f --- /dev/null +++ b/src/ci2_try.c @@ -0,0 +1,798 @@ +/* - | Copyright / About | ---------------------------------------------------- + Copyright (c) 2026 Randy Jordan + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +This is the ci2_try.h Implementation. The functions are just wrappers for the +general c libraries. If they fail they raise an exception with macro magic. All +other functions that may raise an exception are in include/platform/mem. It's +not recommended to use these functions, as they are hard to debug and it's not +a robust way to handle errors. + + * --------------------------------------------------------------------------*/ + +#include "../include/platform/error/ci2_exception.h" // Exceptions +#include "../include/platform/try/ci2_try.h" + +/* fcntl.h */ +int +ci2_try_creat(const char* path, mode_t mode); + +int +ci2_try_fcntl(int fd, int cmd, long args); + +int +ci2_try_open(const char* pathname, int flags, mode_t mode); + +/* socket.h */ +int +ci2_try_accept(int, struct sockaddr* restrict, socklen_t* restrict); + +int +ci2_try_bind(int, const struct sockaddr*, socklen_t); + +int +ci2_try_connect(int, const struct sockaddr*, socklen_t); + +int +ci2_try_getpeername(int, struct sockaddr* restrict, socklen_t* restrict); + +int +ci2_try_getsockname(int, struct sockaddr* restrict, socklen_t* restrict); + +int +ci2_try_getsockopt(int, int, int, void* restrict, socklen_t* restrict); + +int +ci2_try_listen(int, int); + +ssize_t +ci2_try_recv(int, void*, size_t, int); + +ssize_t +ci2_try_recvfrom(int, + void* restrict, + size_t, + int, + struct sockaddr* restrict, + socklen_t* restrict); + +ssize_t +ci2_try_recvmsg(int, struct msghdr*, int); + +ssize_t +ci2_try_send(int, const void*, size_t, int); + +ssize_t +ci2_try_sendmsg(int, const struct msghdr*, int); + +ssize_t +ci2_try_sendto(int, + const void*, + size_t, + int, + const struct sockaddr*, + socklen_t); + +int +ci2_try_setsockopt(int, int, int, const void*, socklen_t); + +int +ci2_try_shutdown(int, int); + +int +ci2_try_sockatmark(int); + +int +ci2_try_socket(int, int, int); + +int +ci2_try_socketpair(int, int, int, int[2]); + +/* sys/stat.h */ + +int +ci2_try_chmod(const char*, mode_t); + +int +ci2_try_fchmod(int, mode_t); + +int +ci2_try_fchmodat(int, const char*, mode_t, int); + +int +ci2_try_fstat(int, struct stat*); + +int +ci2_try_fstatat(int, const char* restrict, struct stat* restrict, int); + +int +ci2_try_futimens(int, const struct timespec[2]); + +int +ci2_try_lstat(const char* restrict, struct stat* restrict); + +int +ci2_try_mkdir(const char*, mode_t); + +int +ci2_try_mkdirat(int, const char*, mode_t); + +int +ci2_try_mkfifo(const char*, mode_t); + +int +ci2_try_mkfifoat(int, const char*, mode_t); + +int +ci2_try_mknod(const char*, mode_t, dev_t); + +int +ci2_try_mknodat(int, const char*, mode_t, dev_t); + +int +ci2_try_stat(const char* restrict, struct stat* restrict); + +mode_t ci2_try_umask(mode_t); + +int +ci2_try_utimensat(int, const char*, const struct timespec[2], int); + +/* unistd.h */ +int +ci2_try_access(const char*, int); + +unsigned +ci2_try_alarm(unsigned); + +int +ci2_try_chdir(const char*); + +int +ci2_try_chown(const char*, uid_t, gid_t); + +int +ci2_try_close(int); + +size_t +ci2_try_confstr(int, char*, size_t); + +char* +ci2_try_crypt(const char*, const char*); + +int +ci2_try_dup(int); + +int +ci2_try_dup2(int, int); + +void +ci2_try_exit(int); + +void +ci2_try_encrypt(char[64], int); + +int +ci2_try_execl(const char*, const char*, ...); + +int +ci2_try_execle(const char*, const char*, ...); + +int +ci2_try_execlp(const char*, const char*, ...); + +int +ci2_try_execv(const char*, char* const[]); + +int +ci2_try_execve(const char*, char* const[], char* const[]); + +int +ci2_try_execvp(const char*, char* const[]); + +int +ci2_try_faccessat(int, const char*, int, int); + +int +ci2_try_fchdir(int); + +int +ci2_try_fchown(int, uid_t, gid_t); + +int +ci2_try_fchownat(int, const char*, uid_t, gid_t, int); + +int +ci2_try_fdatasync(int); + +int +ci2_try_fexecve(int, char* const[], char* const[]); + +pid_t +ci2_try_fork(void); + +long +ci2_try_fpathconf(int, int); + +int +ci2_try_fsync(int); + +int +ci2_try_ftruncate(int, off_t); + +char* +ci2_try_getcwd(char*, size_t); + +gid_t +ci2_try_getegid(void); + +uid_t +ci2_try_geteuid(void); + +gid_t +ci2_try_getgid(void); + +int +ci2_try_getgroups(int, gid_t[]); + +long +ci2_try_gethostid(void); + +int +ci2_try_gethostname(char*, size_t); + +char* +ci2_try_getlogin(void); + +int +ci2_try_getlogin_r(char*, size_t); + +int +ci2_try_getopt(int, char* const[], const char*); + +pid_t ci2_try_getpgid(pid_t); + +pid_t +ci2_try_getpgrp(void); + +pid_t +ci2_try_getpid(void); + +pid_t +ci2_try_getppid(void); + +pid_t ci2_try_getsid(pid_t); + +uid_t +ci2_try_getuid(void); + +int +ci2_try_isatty(int); + +int +ci2_try_lchown(const char*, uid_t, gid_t); + +int +ci2_try_link(const char*, const char*); + +int +ci2_try_linkat(int, const char*, int, const char*, int); + +int +ci2_try_lockf(int, int, off_t); + +off_t +ci2_try_lseek(int, off_t, int); + +int +ci2_try_nice(int); + +long +ci2_try_pathconf(const char*, int); + +int +ci2_try_pause(void); + +int +ci2_try_pipe(int[2]); + +ssize_t +ci2_try_pread(int, void*, size_t, off_t); + +ssize_t +ci2_try_pwrite(int, const void*, size_t, off_t); + +ssize_t +ci2_try_read(int, void*, size_t); + +ssize_t +ci2_try_readlink(const char* restrict, char* restrict, size_t); + +ssize_t +ci2_try_readlinkat(int, const char* restrict, char* restrict, size_t); + +int +ci2_try_rmdir(const char*); + +int ci2_try_setegid(gid_t); + +int ci2_try_seteuid(uid_t); + +int ci2_try_setgid(gid_t); + +int ci2_try_setpgid(pid_t, pid_t); + +pid_t +ci2_try_setpgrp(void); + +int ci2_try_setregid(gid_t, gid_t); + +int ci2_try_setreuid(uid_t, uid_t); + +pid_t +ci2_try_setsid(void); + +int ci2_try_setuid(uid_t); + +unsigned +ci2_try_sleep(unsigned); + +void +ci2_try_swab(const void* restrict, void* restrict, ssize_t); + +int +ci2_try_symlink(const char*, const char*); + +int +ci2_try_symlinkat(const char*, int, const char*); + +void +ci2_try_sync(void); + +long +ci2_try_sysconf(int); + +pid_t +ci2_try_tcgetpgrp(int); + +int +ci2_try_tcsetpgrp(int, pid_t); + +int +ci2_try_truncate(const char*, off_t); + +char* +ci2_try_ttyname(int); + +int +ci2_try_ttyname_r(int, char*, size_t); + +int +ci2_try_unlink(const char*); + +int +ci2_try_unlinkat(int, const char*, int); + +ssize_t +ci2_try_write(int, const void*, size_t); + +/* stdio.h */ +void +ci2_try_clearerr(FILE*); + +char* +ci2_try_ctermid(char*); + +int +ci2_try_dprintf(int, const char* restrict, ...); + +int +ci2_try_fclose(FILE*); + +FILE* +ci2_try_fdopen(int, const char*); + +int +ci2_try_feof(FILE*); + +int +ci2_try_ferror(FILE*); + +int +ci2_try_fflush(FILE*); + +int +ci2_try_fgetc(FILE*); + +int +ci2_try_fgetpos(FILE* restrict, fpos_t* restrict); + +char* +ci2_try_fgets(char* restrict, int, FILE* restrict); + +int +ci2_try_fileno(FILE*); + +void +ci2_try_flockfile(FILE*); + +FILE* +ci2_try_fmemopen(void* restrict, size_t, const char* restrict); + +FILE* +ci2_try_fopen(const char* restrict, const char* restrict); + +int +ci2_try_fprintf(FILE* restrict, const char* restrict, ...); + +int +ci2_try_fputc(int, FILE*); + +int +ci2_try_fputs(const char* restrict, FILE* restrict); + +size_t +ci2_try_fread(void* restrict, size_t, size_t, FILE* restrict); + +FILE* +ci2_try_freopen(const char* restrict, const char* restrict, FILE* restrict); + +int +ci2_try_fscanf(FILE* restrict, const char* restrict, ...); + +int +ci2_try_fseek(FILE*, long, int); + +int +ci2_try_fseeko(FILE*, off_t, int); + +int +ci2_try_fsetpos(FILE*, const fpos_t*); + +long +ci2_try_ftell(FILE*); + +off_t +ci2_try_ftello(FILE*); + +int +ci2_try_ftrylockfile(FILE*); + +void +ci2_try_funlockfile(FILE*); + +size_t +ci2_try_fwrite(const void* restrict, size_t, size_t, FILE* restrict); + +int +ci2_try_getc(FILE*); + +int +ci2_try_getchar(void); + +int +ci2_try_getc_unlocked(FILE*); + +int +ci2_try_getchar_unlocked(void); + +ssize_t +ci2_try_getdelim(char** restrict, size_t* restrict, int, FILE* restrict); + +ssize_t +ci2_try_getline(char** restrict, size_t* restrict, FILE* restrict); + +char* +ci2_try_gets(char*); + +FILE* +ci2_try_open_memstream(char**, size_t*); + +int +ci2_try_pclose(FILE*); + +void +ci2_try_perror(const char*); + +FILE* +ci2_try_popen(const char*, const char*); + +int +ci2_try_printf(const char* restrict, ...); + +int +ci2_try_putc(int, FILE*); + +int +ci2_try_putchar(int); + +int +ci2_try_putc_unlocked(int, FILE*); + +int +ci2_try_putchar_unlocked(int); + +int +ci2_try_puts(const char*); + +int +ci2_try_remove(const char*); + +int +ci2_try_rename(const char*, const char*); + +int +ci2_try_renameat(int, const char*, int, const char*); + +void +ci2_try_rewind(FILE*); + +int +ci2_try_scanf(const char* restrict, ...); + +void +ci2_try_setbuf(FILE* restrict, char* restrict); + +int +ci2_try_setvbuf(FILE* restrict, char* restrict, int, size_t); + +int +ci2_try_snprintf(char* restrict, size_t, const char* restrict, ...); + +int +ci2_try_sprintf(char* restrict, const char* restrict, ...); + +int +ci2_try_sscanf(const char* restrict, const char* restrict, ...); + +char* +ci2_try_tempnam(const char*, const char*); + +FILE* +ci2_try_tmpfile(void); + +char* +ci2_try_tmpnam(char*); + +int +ci2_try_ungetc(int, FILE*); + +int +ci2_try_vdprintf(int, const char* restrict, va_list); + +int +ci2_try_vfprintf(FILE* restrict, const char* restrict, va_list); + +int +ci2_try_vfscanf(FILE* restrict, const char* restrict, va_list); + +int +ci2_try_vprintf(const char* restrict, va_list); + +int +ci2_try_vscanf(const char* restrict, va_list); + +int +ci2_try_vsnprintf(char* restrict, size_t, const char* restrict, va_list); + +int +ci2_try_vsprintf(char* restrict, const char* restrict, va_list); + +int +ci2_try_vsscanf(const char* restrict, const char* restrict, va_list); + +/* stdlib.h */ +void +ci2_try_Exit(int); + +long +ci2_try_a64l(const char*); + +void +ci2_try_abort(void); + +int +ci2_try_abs(int); + +int +ci2_try_atexit(void (*)(void)); + +double +ci2_try_atof(const char*); + +int +ci2_try_atoi(const char*); + +long +ci2_try_atol(const char*); + +long long +ci2_try_atoll(const char*); + +void* +ci2_try_bsearch(const void*, + const void*, + size_t, + size_t, + int (*)(const void*, const void*)); + +void* +ci2_try_calloc(size_t, size_t); + +div_t +ci2_try_div(int, int); + +double +ci2_try_drand48(void); + +double +ci2_try_erand48(unsigned short[3]); + +void +ci2_try_exit(int); + +void +ci2_try_free(void*); + +char* +ci2_try_getenv(const char*); + +int +ci2_try_getsubopt(char**, char* const*, char**); + +int +ci2_try_grantpt(int); + +char* +ci2_try_initstate(unsigned, char*, size_t); + +long +ci2_try_jrand48(unsigned short[3]); + +char* +ci2_try_l64a(long); + +long +ci2_try_labs(long); + +void +ci2_try_lcong48(unsigned short[7]); + +ldiv_t +ci2_try_ldiv(long, long); + +long long +ci2_try_llabs(long long); + +lldiv_t +ci2_try_lldiv(long long, long long); + +long +ci2_try_lrand48(void); + +void* +ci2_try_malloc(size_t); + +int +ci2_try_mblen(const char*, size_t); + +size_t +ci2_try_mbstowcs(wchar_t* restrict, const char* restrict, size_t); + +int +ci2_try_mbtowc(wchar_t* restrict, const char* restrict, size_t); + +char* +ci2_try_mkdtemp(char*); + +int +ci2_try_mkstemp(char*); + +long +ci2_try_mrand48(void); + +long +ci2_try_nrand48(unsigned short[3]); + +int +ci2_try_posix_memalign(void**, size_t, size_t); + +int +ci2_try_posix_openpt(int); + +char* +ci2_try_ptsname(int); + +int +ci2_try_putenv(char*); + +void +ci2_try_qsort(void*, size_t, size_t, int (*)(const void*, const void*)); + +int +ci2_try_rand(void); + +int +ci2_try_rand_r(unsigned*); + +long +ci2_try_random(void); + +void* +ci2_try_realloc(void*, size_t); + +char* +ci2_try_realpath(const char* restrict, char* restrict); + +unsigned short* +ci2_try_seed48(unsigned short[3]); + +int +ci2_try_setenv(const char*, const char*, int); + +void +ci2_try_setkey(const char*); + +char* +ci2_try_setstate(char*); + +void +ci2_try_srand(unsigned); + +void +ci2_try_srand48(long); + +void +ci2_try_srandom(unsigned); + +double +ci2_try_strtod(const char* restrict, char** restrict); + +float +ci2_try_strtof(const char* restrict, char** restrict); + +long +ci2_try_strtol(const char* restrict, char** restrict, int); + +long double +ci2_try_strtold(const char* restrict, char** restrict); + +long long +ci2_try_strtoll(const char* restrict, char** restrict, int); + +unsigned long +ci2_try_strtoul(const char* restrict, char** restrict, int); + +unsigned long long +ci2_try_strtoull(const char* restrict, char** restrict, int); + +int +ci2_try_system(const char*); + +int +ci2_try_unlockpt(int); + +int +ci2_try_unsetenv(const char*); + +size_t +ci2_try_wcstombs(char* restrict, const wchar_t* restrict, size_t); + +int +ci2_try_wctomb(char*, wchar_t);