Files
haiku-beta6/src/tools/fs_shell/fcntl.cpp
T
Ingo Weinhold 3e61704042 axeld + bonefish:
Added parameters --start-offset and --end-offset to restrict the
access of the file system to only that part of the given file.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23970 a95241bf-73f2-0310-859d-f6bbb57e9c96
2008-02-17 13:42:27 +00:00

66 lines
1.2 KiB
C++

/*
* Copyright 2007-2008, Ingo Weinhold, [email protected].
* Distributed under the terms of the MIT License.
*/
#include "fssh_fcntl.h"
#include <fcntl.h>
#include <stdarg.h>
#include "fssh_errno.h"
#include "partition_support.h"
#include "stat_util.h"
using namespace FSShell;
#ifndef __BEOS__
// The _kern_open() defined in libroot_build.so.
extern "C" int _kern_open(int fd, const char *path, int openMode,
int perms);
#endif
int
fssh_open(const char *pathname, int oflags, ...)
{
va_list args;
va_start(args, oflags);
// get the mode, if O_CREAT was specified
fssh_mode_t mode = 0;
if (oflags & FSSH_O_CREAT)
mode = va_arg(args, fssh_mode_t);
va_end(args);
// Use the _kern_open() defined in libroot on BeOS incompatible systems.
// Required for proper attribute emulation support.
int fd;
#if __BEOS__
fd = open(pathname, to_platform_open_mode(oflags),
to_platform_mode(mode));
#else
fd = _kern_open(-1, pathname, to_platform_open_mode(oflags),
to_platform_mode(mode));
if (fd < 0) {
fssh_set_errno(fd);
fd = -1;
}
#endif
restricted_file_opened(fd);
return fd;
}
int
fssh_creat(const char *path, fssh_mode_t mode)
{
return fssh_open(path, FSSH_O_WRONLY | FSSH_O_CREAT | FSSH_O_TRUNC, mode);
}