* The build platform fstat() wrapper moved into stat_util.cpp/h.

* Added wrappers for open(), close(), and read_pos().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11582 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2005-03-05 20:34:39 +00:00
parent d29e55d8ec
commit edbadbb0f3

View File

@ -261,10 +261,81 @@ writev_pos(int fd, fs_off_t _pos, struct iovec *iov, int count)
}
int fs_shell_fstat(int fd, struct my_stat *myst);
static int
to_platform_open_mode(int myMode)
{
#define SET_OPEN_MODE_FLAG(flag, myFlag) \
if (myMode & myFlag) \
mode |= flag;
int mode = 0;
// the r/w mode
switch (myMode & MY_O_RWMASK) {
case MY_O_RDONLY:
mode |= O_RDONLY;
break;
case MY_O_WRONLY:
mode |= O_WRONLY;
break;
case MY_O_RDWR:
mode |= O_RDWR;
break;
}
// the flags
SET_OPEN_MODE_FLAG(O_CLOEXEC, MY_O_CLOEXEC)
SET_OPEN_MODE_FLAG(O_NONBLOCK, MY_O_NONBLOCK)
SET_OPEN_MODE_FLAG(O_EXCL, MY_O_EXCL)
SET_OPEN_MODE_FLAG(O_CREAT, MY_O_CREAT)
SET_OPEN_MODE_FLAG(O_TRUNC, MY_O_TRUNC)
SET_OPEN_MODE_FLAG(O_APPEND, MY_O_APPEND)
SET_OPEN_MODE_FLAG(O_NOCTTY, MY_O_NOCTTY)
SET_OPEN_MODE_FLAG(O_NOTRAVERSE, MY_O_NOTRAVERSE)
SET_OPEN_MODE_FLAG(O_ACCMODE, MY_O_ACCMODE)
SET_OPEN_MODE_FLAG(O_TEXT, MY_O_TEXT)
SET_OPEN_MODE_FLAG(O_BINARY, MY_O_BINARY)
#undef SET_OPEN_MODE_FLAG
return myFlags;
}
int build_platform_open(const char *pathname, int oflags, my_mode_t mode);
int
fs_shell_fstat(int fd, struct my_stat *myst)
build_platform_open(const char *pathname, int oflags, my_mode_t mode)
{
int fd = open(pathname, to_platform_open_mode(oflags),
to_platform_mode(mode));
if (fd < 0) {
errno = from_platform_error(errno);
return -1;
}
return fd;
}
int build_platform_close(int fd);
int
build_platform_close(int fd)
{
if (close(fd) < 0) {
errno = from_platform_error(errno);
return -1;
}
return 0;
}
int build_platform_fstat(int fd, struct my_stat *myst);
int
build_platform_fstat(int fd, struct my_stat *myst)
{
struct stat st;
@ -278,111 +349,27 @@ fs_shell_fstat(int fd, struct my_stat *myst)
return -1;
}
// translate the stat structure
myst->dev = st.st_dev;
myst->ino = st.st_ino;
myst->nlink = st.st_nlink;
myst->uid = st.st_uid;
myst->gid = st.st_gid;
myst->size = st.st_size;
myst->blksize = st.st_blksize;
myst->atime = st.st_atime;
myst->mtime = st.st_mtime;
myst->ctime = st.st_ctime;
myst->crtime = st.st_ctime;
// translate st_mode
myst->mode = 0;
#define SET_ST_MODE_BIT(flag, myflag) \
if (st.st_mode & flag) \
myst->mode |= myflag;
#ifndef S_ATTR_DIR
#define S_ATTR_DIR 0
#endif
#ifndef S_ATTR
#define S_ATTR 0
#endif
#ifndef S_INDEX_DIR
#define S_INDEX_DIR 0
#endif
#ifndef S_INT_INDEX
#define S_INT_INDEX 0
#endif
#ifndef S_UINT_INDEX
#define S_UINT_INDEX 0
#endif
#ifndef S_LONG_LONG_INDEX
#define S_LONG_LONG_INDEX 0
#endif
#ifndef S_ULONG_LONG_INDEX
#define S_ULONG_LONG_INDEX 0
#endif
#ifndef S_FLOAT_INDEX
#define S_FLOAT_INDEX 0
#endif
#ifndef S_DOUBLE_INDEX
#define S_DOUBLE_INDEX 0
#endif
#ifndef S_ALLOW_DUPS
#define S_ALLOW_DUPS 0
#endif
#ifndef S_LINK_SELF_HEALING
#define S_LINK_SELF_HEALING 0
#endif
#ifndef S_LINK_AUTO_DELETE
#define S_LINK_AUTO_DELETE 0
#endif
SET_ST_MODE_BIT(MY_S_ATTR_DIR, S_ATTR_DIR);
SET_ST_MODE_BIT(MY_S_ATTR, S_ATTR);
SET_ST_MODE_BIT(MY_S_INDEX_DIR, S_INDEX_DIR);
SET_ST_MODE_BIT(MY_S_INT_INDEX, S_INT_INDEX);
SET_ST_MODE_BIT(MY_S_UINT_INDEX, S_UINT_INDEX);
SET_ST_MODE_BIT(MY_S_LONG_LONG_INDEX, S_LONG_LONG_INDEX);
SET_ST_MODE_BIT(MY_S_ULONG_LONG_INDEX, S_ULONG_LONG_INDEX);
SET_ST_MODE_BIT(MY_S_FLOAT_INDEX, S_FLOAT_INDEX);
SET_ST_MODE_BIT(MY_S_DOUBLE_INDEX, S_DOUBLE_INDEX);
SET_ST_MODE_BIT(MY_S_ALLOW_DUPS, S_ALLOW_DUPS);
SET_ST_MODE_BIT(MY_S_LINK_SELF_HEALING, S_LINK_SELF_HEALING);
SET_ST_MODE_BIT(MY_S_LINK_AUTO_DELETE, S_LINK_AUTO_DELETE);
switch (st.st_mode & S_IFMT) {
case S_IFLNK:
myst->mode |= MY_S_IFLNK;
break;
case S_IFREG:
myst->mode |= MY_S_IFREG;
break;
case S_IFBLK:
myst->mode |= MY_S_IFBLK;
break;
case S_IFDIR:
myst->mode |= MY_S_IFDIR;
break;
case S_IFIFO:
myst->mode |= MY_S_IFIFO;
break;
}
SET_ST_MODE_BIT(MY_S_ISUID, S_ISUID);
SET_ST_MODE_BIT(MY_S_ISGID, S_ISGID);
SET_ST_MODE_BIT(MY_S_ISVTX, S_ISVTX);
SET_ST_MODE_BIT(MY_S_IRUSR, S_IRUSR);
SET_ST_MODE_BIT(MY_S_IWUSR, S_IWUSR);
SET_ST_MODE_BIT(MY_S_IXUSR, S_IXUSR);
SET_ST_MODE_BIT(MY_S_IRGRP, S_IRGRP);
SET_ST_MODE_BIT(MY_S_IWGRP, S_IWGRP);
SET_ST_MODE_BIT(MY_S_IXGRP, S_IXGRP);
SET_ST_MODE_BIT(MY_S_IROTH, S_IROTH);
SET_ST_MODE_BIT(MY_S_IWOTH, S_IWOTH);
SET_ST_MODE_BIT(MY_S_IXOTH, S_IXOTH);
from_platform_stat(&st, myst);
return 0;
}
ssize_t build_platform_read_pos(int fd, fs_off_t pos, void *buf, size_t count);
ssize_t
build_platform_read_pos(int fd, fs_off_t pos, void *buf, size_t count)
{
ssize_t result = read_pos(fd, pos, buf, count);
if (result < 0) {
errno = from_platform_error(errno);
return -1;
}
return result;
}
#endif /* ! __BEOS__ */