meta: rename to fx
This commit is contained in:
@@ -1,131 +1,131 @@
|
||||
#include <blue/core/error.h>
|
||||
#include <blue/core/status.h>
|
||||
#include <blue/io/file.h>
|
||||
#include <fx/core/error.h>
|
||||
#include <fx/core/status.h>
|
||||
#include <fx/io/file.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
enum b_status b_status_from_errno(int error, enum b_status default_value)
|
||||
enum fx_status fx_status_from_errno(int error, enum fx_status default_value)
|
||||
{
|
||||
switch (error) {
|
||||
case 0:
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
case ENOENT:
|
||||
return B_ERR_NO_ENTRY;
|
||||
return FX_ERR_NO_ENTRY;
|
||||
case EEXIST:
|
||||
return B_ERR_NAME_EXISTS;
|
||||
return FX_ERR_NAME_EXISTS;
|
||||
case ENOMEM:
|
||||
return B_ERR_NO_MEMORY;
|
||||
return FX_ERR_NO_MEMORY;
|
||||
case EINVAL:
|
||||
return B_ERR_INVALID_ARGUMENT;
|
||||
return FX_ERR_INVALID_ARGUMENT;
|
||||
case EIO:
|
||||
return B_ERR_IO_FAILURE;
|
||||
return FX_ERR_IO_FAILURE;
|
||||
case EISDIR:
|
||||
return B_ERR_IS_DIRECTORY;
|
||||
return FX_ERR_IS_DIRECTORY;
|
||||
case ENOTDIR:
|
||||
return B_ERR_NOT_DIRECTORY;
|
||||
return FX_ERR_NOT_DIRECTORY;
|
||||
case EPERM:
|
||||
case EACCES:
|
||||
return B_ERR_PERMISSION_DENIED;
|
||||
return FX_ERR_PERMISSION_DENIED;
|
||||
case ENOTSUP:
|
||||
case ENOSYS:
|
||||
return B_ERR_NOT_SUPPORTED;
|
||||
return FX_ERR_NOT_SUPPORTED;
|
||||
default:
|
||||
return default_value;
|
||||
}
|
||||
}
|
||||
|
||||
b_result b_result_from_errno_with_filepath(
|
||||
int error, const char *path, enum b_status default_value)
|
||||
fx_result fx_result_from_errno_with_filepath(
|
||||
int error, const char *path, enum fx_status default_value)
|
||||
{
|
||||
switch (error) {
|
||||
case 0:
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
case ENOENT:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_NO_ENTRY, "Path @i{%s} does not exist", path);
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_NO_ENTRY, "Path @i{%s} does not exist", path);
|
||||
case ENOTDIR:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_NOT_DIRECTORY, "Path @i{%s} is not a directory",
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_NOT_DIRECTORY, "Path @i{%s} is not a directory",
|
||||
path);
|
||||
case EISDIR:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_IS_DIRECTORY, "Path @i{%s} is a directory", path);
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_IS_DIRECTORY, "Path @i{%s} is a directory", path);
|
||||
case EPERM:
|
||||
case EACCES:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_PERMISSION_DENIED,
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_PERMISSION_DENIED,
|
||||
"Permission denied while accessing path @i{%s}", path);
|
||||
default:
|
||||
return B_RESULT_STATUS(b_status_from_errno(error, default_value));
|
||||
return FX_RESULT_STATUS(fx_status_from_errno(error, default_value));
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
b_result b_result_from_errno_with_subfilepath(
|
||||
fx_result fx_result_from_errno_with_subfilepath(
|
||||
int error, const char *path, const char *dir_path,
|
||||
enum b_status default_value)
|
||||
enum fx_status default_value)
|
||||
{
|
||||
if (!dir_path) {
|
||||
return b_result_propagate(b_result_from_errno_with_filepath(
|
||||
return fx_result_propagate(fx_result_from_errno_with_filepath(
|
||||
error, path, default_value));
|
||||
}
|
||||
|
||||
switch (error) {
|
||||
case 0:
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
case ENOENT:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_NO_ENTRY,
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_NO_ENTRY,
|
||||
"Path @i{%s} in directory @i{%s} does not exist", path,
|
||||
dir_path);
|
||||
case ENOTDIR:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_NOT_DIRECTORY,
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_NOT_DIRECTORY,
|
||||
"Path @i{%s} in directory @i{%s} is not a directory",
|
||||
path, dir_path);
|
||||
case EISDIR:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_IS_DIRECTORY,
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_IS_DIRECTORY,
|
||||
"Path @i{%s} in directory @i{%s} is a directory", path,
|
||||
dir_path);
|
||||
case EPERM:
|
||||
case EACCES:
|
||||
return B_RESULT_STATUS_WITH_STRING(
|
||||
B_ERR_PERMISSION_DENIED,
|
||||
return FX_RESULT_STATUS_WITH_STRING(
|
||||
FX_ERR_PERMISSION_DENIED,
|
||||
"Permission denied while accessing path @i{%s} in "
|
||||
"directory @i{%s}",
|
||||
path, dir_path);
|
||||
default:
|
||||
return B_RESULT_STATUS(b_status_from_errno(error, default_value));
|
||||
return FX_RESULT_STATUS(fx_status_from_errno(error, default_value));
|
||||
}
|
||||
|
||||
return B_RESULT_SUCCESS;
|
||||
return FX_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
enum b_status b_file_info_from_stat(const struct stat *st, struct b_file_info *out)
|
||||
enum fx_status fx_file_info_from_stat(const struct stat *st, struct fx_file_info *out)
|
||||
{
|
||||
out->length = st->st_size;
|
||||
|
||||
if (S_ISREG(st->st_mode)) {
|
||||
out->attrib |= B_FILE_ATTRIB_NORMAL;
|
||||
out->attrib |= FX_FILE_ATTRIB_NORMAL;
|
||||
}
|
||||
|
||||
if (S_ISDIR(st->st_mode)) {
|
||||
out->attrib |= B_FILE_ATTRIB_DIRECTORY;
|
||||
out->attrib |= FX_FILE_ATTRIB_DIRECTORY;
|
||||
}
|
||||
|
||||
if (S_ISBLK(st->st_mode)) {
|
||||
out->attrib |= B_FILE_ATTRIB_BLOCK_DEVICE;
|
||||
out->attrib |= FX_FILE_ATTRIB_BLOCK_DEVICE;
|
||||
}
|
||||
|
||||
if (S_ISCHR(st->st_mode)) {
|
||||
out->attrib |= B_FILE_ATTRIB_CHAR_DEVICE;
|
||||
out->attrib |= FX_FILE_ATTRIB_CHAR_DEVICE;
|
||||
}
|
||||
|
||||
if (S_ISLNK(st->st_mode)) {
|
||||
out->attrib |= B_FILE_ATTRIB_SYMLINK;
|
||||
out->attrib |= FX_FILE_ATTRIB_SYMLINK;
|
||||
}
|
||||
|
||||
return B_SUCCESS;
|
||||
return FX_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user