Skip to content

Commit d30afec

Browse files
committed
Translate common host error codes
Caller may reasonably be expected to query some codes, such as 'not found'
1 parent 4437e76 commit d30afec

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/HostUtil.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,32 @@ int mapFlags(OpenFlags flags)
6969
return ret;
7070
}
7171

72+
int syserr()
73+
{
74+
switch(errno) {
75+
case EPERM:
76+
case EACCES:
77+
return Error::Denied;
78+
case ENOMEM:
79+
return Error::NoMem;
80+
case ENOENT:
81+
return Error::NotFound;
82+
case ENFILE:
83+
case EMFILE:
84+
return Error::OutOfFileDescs;
85+
case EFBIG:
86+
return Error::TooBig;
87+
case ENOSPC:
88+
return Error::NoSpace;
89+
case EROFS:
90+
return Error::ReadOnly;
91+
case EINVAL:
92+
return Error::BadParam;
93+
default:
94+
return Error::fromSystem(-errno);
95+
}
96+
}
97+
7298
String getErrorString(int err)
7399
{
74100
if(Error::isSystem(err)) {

src/include/IFS/Host/Util.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ namespace IFS::Host
3434
/**
3535
* @brief Get IFS error code for the current system errno
3636
*/
37-
inline int syserr()
38-
{
39-
return Error::fromSystem(-errno);
40-
}
37+
int syserr();
4138

4239
/**
4340
* @brief Get corresponding host flags for given IFS flags

0 commit comments

Comments
 (0)