Skip to content

Commit

Permalink
util: Add GFileError to errno converter
Browse files Browse the repository at this point in the history
[util] Add GFileError to errno converter. JB#61966

Map the errors in G_FILE_ERROR domain to matching errnos. Return
-EBADMSG if error is NULL and -ENOTSUP when domain is not G_FILE_ERROR.
  • Loading branch information
LaakkonenJussi committed Jan 24, 2025
1 parent ac03693 commit 253f52a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
60 changes: 59 additions & 1 deletion connman/src/shared/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,64 @@ static bool is_file_symlink(const char *filename)
return false;
}

int util_g_file_error_to_errno(int code)
{
switch (code) {
case G_FILE_ERROR_EXIST:
return -EEXIST;
case G_FILE_ERROR_ISDIR:
return -EISDIR;
case G_FILE_ERROR_ACCES:
return -EACCES;
case G_FILE_ERROR_NAMETOOLONG:
return -ENAMETOOLONG;
case G_FILE_ERROR_NOENT:
return -ENOENT;
case G_FILE_ERROR_NOTDIR:
return -ENOTDIR;
case G_FILE_ERROR_NXIO:
return -ENXIO;
case G_FILE_ERROR_NODEV:
return -ENODEV;
case G_FILE_ERROR_ROFS:
return -EROFS;
case G_FILE_ERROR_TXTBSY:
return -ETXTBSY;
case G_FILE_ERROR_FAULT:
return -EFAULT;
case G_FILE_ERROR_LOOP:
return -ELOOP;
case G_FILE_ERROR_NOSPC:
return -ENOSPC;
case G_FILE_ERROR_NOMEM:
return -ENOMEM;
case G_FILE_ERROR_MFILE:
return -EMFILE;
case G_FILE_ERROR_NFILE:
return -ENFILE;
case G_FILE_ERROR_BADF:
return EBADF;
case G_FILE_ERROR_INVAL:
return -EINVAL;
case G_FILE_ERROR_PIPE:
return -EPIPE;
case G_FILE_ERROR_AGAIN:
return -EAGAIN;
case G_FILE_ERROR_INTR:
return -EINTR;
case G_FILE_ERROR_IO:
return -EIO;
case G_FILE_ERROR_PERM:
return -EPERM;
case G_FILE_ERROR_NOSYS:
return -ENOSYS;
case G_FILE_ERROR_FAILED:
return -EINVAL;
}

return -EINVAL;
}

int util_read_config_files_from(const char *path, const char *suffix,
GList **conffiles, config_callback cb)
{
Expand All @@ -207,7 +265,7 @@ int util_read_config_files_from(const char *path, const char *suffix,
if (error) {
connman_warn("cannot open dir %s, error: %s", path,
error->message);
err = -error->code;
err = util_g_file_error_to_errno(error->code);
} else {
err = -ENOMEM;
}
Expand Down
1 change: 1 addition & 0 deletions connman/src/shared/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ bool util_get_afs(bool *afs, int family);
void util_reset_afs(bool *afs);

typedef int (*config_callback) (const char *filepath);
int util_g_file_error_to_errno(int code);
int util_read_config_files_from(const char *path, const char *suffix,
GList **conffiles, config_callback cb);

0 comments on commit 253f52a

Please sign in to comment.