59 lines
1.1 KiB
C
59 lines
1.1 KiB
C
#include <blue/core/status.h>
|
|
#include <blue/io/file.h>
|
|
#include <errno.h>
|
|
#include <sys/stat.h>
|
|
|
|
enum b_status b_status_from_errno(int error, enum b_status default_value)
|
|
{
|
|
switch (error) {
|
|
case 0:
|
|
return B_SUCCESS;
|
|
case ENOENT:
|
|
return B_ERR_NO_ENTRY;
|
|
case EEXIST:
|
|
return B_ERR_NAME_EXISTS;
|
|
case ENOMEM:
|
|
return B_ERR_NO_MEMORY;
|
|
case EINVAL:
|
|
return B_ERR_INVALID_ARGUMENT;
|
|
case EIO:
|
|
return B_ERR_IO_FAILURE;
|
|
case EISDIR:
|
|
return B_ERR_IS_DIRECTORY;
|
|
case ENOTDIR:
|
|
return B_ERR_NOT_DIRECTORY;
|
|
case ENOTSUP:
|
|
case ENOSYS:
|
|
return B_ERR_NOT_SUPPORTED;
|
|
default:
|
|
return default_value;
|
|
}
|
|
}
|
|
|
|
enum b_status b_file_info_from_stat(const struct stat *st, struct b_file_info *out)
|
|
{
|
|
out->length = st->st_size;
|
|
|
|
if (S_ISREG(st->st_mode)) {
|
|
out->attrib |= B_FILE_ATTRIB_NORMAL;
|
|
}
|
|
|
|
if (S_ISDIR(st->st_mode)) {
|
|
out->attrib |= B_FILE_ATTRIB_DIRECTORY;
|
|
}
|
|
|
|
if (S_ISBLK(st->st_mode)) {
|
|
out->attrib |= B_FILE_ATTRIB_BLOCK_DEVICE;
|
|
}
|
|
|
|
if (S_ISCHR(st->st_mode)) {
|
|
out->attrib |= B_FILE_ATTRIB_CHAR_DEVICE;
|
|
}
|
|
|
|
if (S_ISLNK(st->st_mode)) {
|
|
out->attrib |= B_FILE_ATTRIB_SYMLINK;
|
|
}
|
|
|
|
return B_SUCCESS;
|
|
}
|