Fix FreeBSD build.
[haiku.git] / src / tools / fs_shell / fcntl.cpp
blobab63c1a0abd251ef1f0d347a9b6a169e461cad39
1 /*
2 * Copyright 2007-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
6 #include "fssh_fcntl.h"
8 #include <fcntl.h>
9 #include <stdarg.h>
11 #include "fssh_errno.h"
12 #include "partition_support.h"
13 #include "stat_util.h"
16 using namespace FSShell;
19 #if (!defined(__BEOS__) && !defined(__HAIKU__))
20 // The _kern_open() defined in libroot_build.so.
21 # define _kern_open _kernbuild_open
22 extern "C" int _kern_open(int fd, const char *path, int openMode,
23 int perms);
24 #endif
27 int
28 fssh_open(const char *pathname, int oflags, ...)
30 va_list args;
31 va_start(args, oflags);
33 // get the mode, if O_CREAT was specified
34 fssh_mode_t mode = 0;
35 if (oflags & FSSH_O_CREAT)
36 mode = va_arg(args, fssh_mode_t);
38 va_end(args);
40 // Use the _kern_open() defined in libroot on BeOS incompatible systems.
41 // Required for proper attribute emulation support.
42 int fd;
43 #if (defined(__BEOS__) || defined(__HAIKU__))
44 fd = open(pathname, to_platform_open_mode(oflags),
45 to_platform_mode(mode));
46 #else
47 fd = _kern_open(-1, pathname, to_platform_open_mode(oflags),
48 to_platform_mode(mode));
49 if (fd < 0) {
50 fssh_set_errno(fd);
51 fd = -1;
54 #endif
56 restricted_file_opened(fd);
58 return fd;
62 int
63 fssh_creat(const char *path, fssh_mode_t mode)
65 return fssh_open(path, FSSH_O_WRONLY | FSSH_O_CREAT | FSSH_O_TRUNC, mode);