More try progress
This commit is contained in:
+259
-26
@@ -408,10 +408,30 @@ ci2_try_lstat(const char* restrict path, struct stat* restrict buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_mkdir(const char*, mode_t);
|
ci2_try_mkdir(const char* path, mode_t mode)
|
||||||
|
{
|
||||||
|
int res = mkdir(path, mode);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_mkdirat(int, const char*, mode_t);
|
ci2_try_mkdirat(int dirfd, const char* path, mode_t mode)
|
||||||
|
{
|
||||||
|
int res = mkdirat(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
|
int
|
||||||
ci2_try_mkfifo(const char* path, mode_t mode)
|
ci2_try_mkfifo(const char* path, mode_t mode)
|
||||||
@@ -440,31 +460,95 @@ ci2_try_mkfifoat(int dirfd, const char* path, mode_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_mknod(const char*, mode_t, dev_t);
|
ci2_try_mknod(const char* path, mode_t mode, dev_t dev)
|
||||||
|
{
|
||||||
|
int res = mknod(path, mode, dev);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_mknodat(int, const char*, mode_t, dev_t);
|
ci2_try_mknodat(int dirfd, const char* path, mode_t mode, dev_t dev)
|
||||||
|
{
|
||||||
|
int res = mknodat(dirfd, path, mode, dev);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_stat(const char* restrict, struct stat* restrict);
|
ci2_try_stat(const char* restrict path, struct stat* restrict buf)
|
||||||
|
{
|
||||||
|
int res = stat(path, buf);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
mode_t ci2_try_umask(mode_t);
|
mode_t
|
||||||
|
ci2_try_umask(mode_t mode)
|
||||||
|
{ // Always succeeds.
|
||||||
|
return umask(mode);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_utimensat(int, const char*, const struct timespec[2], int);
|
ci2_try_utimensat(int, const char*, const struct timespec[2], int);
|
||||||
|
|
||||||
/* unistd.h */
|
/* unistd.h */
|
||||||
int
|
int
|
||||||
ci2_try_access(const char*, int);
|
ci2_try_access(const char* path, int mode)
|
||||||
|
{
|
||||||
|
int res = access(path, mode);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned
|
unsigned
|
||||||
ci2_try_alarm(unsigned);
|
ci2_try_alarm(unsigned);
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_chdir(const char*);
|
ci2_try_chdir(const char* path)
|
||||||
|
{
|
||||||
|
int res = chdir(path);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_chown(const char*, uid_t, gid_t);
|
ci2_try_chown(const char* path, uid_t owner, gid_t group)
|
||||||
|
{
|
||||||
|
int res = chown(path, owner, group);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_close(int fd)
|
ci2_try_close(int fd)
|
||||||
@@ -480,10 +564,30 @@ ci2_try_close(int fd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
ci2_try_confstr(int, char*, size_t);
|
ci2_try_confstr(int name, char* buf, size_t len)
|
||||||
|
{
|
||||||
|
size_t res = confstr(name, buf, len);
|
||||||
|
if (res == 0 && errno == EINVAL) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
ci2_try_crypt(const char*, const char*);
|
ci2_try_crypt(const char* key, const char* salt)
|
||||||
|
{
|
||||||
|
char* res = crypt(key, salt);
|
||||||
|
if (res == NULL) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_dup(int oldfd)
|
ci2_try_dup(int oldfd)
|
||||||
@@ -512,7 +616,10 @@ ci2_try_dup2(int oldfd, int newfd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ci2_try_exit(int);
|
ci2_try_exit(int status)
|
||||||
|
{
|
||||||
|
exit(status);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ci2_try_encrypt(char[64], int);
|
ci2_try_encrypt(char[64], int);
|
||||||
@@ -566,22 +673,86 @@ ci2_try_execvp(const char* file, char* const argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_faccessat(int, const char*, int, int);
|
ci2_try_faccessat(int dirfd, const char* path, int mode, int flags)
|
||||||
|
{
|
||||||
|
int res = faccessat(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
|
int
|
||||||
ci2_try_fchdir(int);
|
ci2_try_fchdir(int fd)
|
||||||
|
{
|
||||||
|
int res = fchdir(fd);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_fchown(int, uid_t, gid_t);
|
ci2_try_fchown(int fd, uid_t owner, gid_t group)
|
||||||
|
{
|
||||||
|
int res = fchown(fd, owner, group);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_fchownat(int, const char*, uid_t, gid_t, int);
|
ci2_try_fchownat(int dirfd,
|
||||||
|
const char* path,
|
||||||
|
uid_t owner,
|
||||||
|
gid_t group,
|
||||||
|
int flags)
|
||||||
|
{
|
||||||
|
int res = fchownat(dirfd, path, owner, group, flags);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_fdatasync(int);
|
ci2_try_fdatasync(int fd)
|
||||||
|
{
|
||||||
|
int res = fdatasync(fd);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_fexecve(int, char* const[], char* const[]);
|
ci2_try_fexecve(int fd, char* const argv[], char* const envp[])
|
||||||
|
{
|
||||||
|
int res = fexecve(fd, argv, envp);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
pid_t
|
pid_t
|
||||||
ci2_try_fork(void)
|
ci2_try_fork(void)
|
||||||
@@ -597,25 +768,77 @@ ci2_try_fork(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
ci2_try_fpathconf(int, int);
|
ci2_try_fpathconf(int fd, int name)
|
||||||
|
{
|
||||||
|
long res = fpathconf(fd, name);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_fsync(int);
|
ci2_try_fsync(int fd)
|
||||||
|
{
|
||||||
|
int res = fsync(fd);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_ftruncate(int, off_t);
|
ci2_try_ftruncate(int fildes, off_t len)
|
||||||
|
{
|
||||||
|
int res = ftruncate(fildes, len);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
ci2_try_getcwd(char*, size_t);
|
ci2_try_getcwd(char* buf, size_t size)
|
||||||
|
{
|
||||||
|
char* res = getcwd(buf, size);
|
||||||
|
if (res == NULL) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
gid_t
|
gid_t
|
||||||
ci2_try_getegid(void);
|
ci2_try_getegid(void) // Never fails
|
||||||
|
{
|
||||||
|
gid_t res = getegid();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
uid_t
|
uid_t
|
||||||
ci2_try_geteuid(void);
|
ci2_try_geteuid(void) // never fails
|
||||||
|
{
|
||||||
|
gid_t res = geteuid();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
gid_t
|
gid_t
|
||||||
ci2_try_getgid(void);
|
ci2_try_getgid(void) // Never fails
|
||||||
|
{
|
||||||
|
gid_t res = getgid();
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_getgroups(int, gid_t[]);
|
ci2_try_getgroups(int, gid_t[]);
|
||||||
@@ -673,7 +896,17 @@ int
|
|||||||
ci2_try_nice(int);
|
ci2_try_nice(int);
|
||||||
|
|
||||||
long
|
long
|
||||||
ci2_try_pathconf(const char*, int);
|
ci2_try_pathconf(const char* path, int name)
|
||||||
|
{
|
||||||
|
long res = pathconf(path, name);
|
||||||
|
if (res < 0) {
|
||||||
|
int err = errno;
|
||||||
|
char* err_str = strerror(err);
|
||||||
|
struct Exception e = { err_str };
|
||||||
|
CI2_RAISE(e);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ci2_try_pause(void);
|
ci2_try_pause(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user