The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
Loading...
Searching...
No Matches
fcntl.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
sys/types.h
>
4
5
/**
6
* @file fcntl.h
7
* @brief file open flags and open().
8
*
9
* the O_ values are ABI and must match the kernel side in
10
* src/kernel/vfs/file.h exactly.
11
*/
12
13
#define O_RDONLY 0x0000
14
#define O_WRONLY 0x0001
15
#define O_RDWR 0x0002
16
#define O_ACCMODE 0x0003
17
18
// creation and status flags (any combination)
19
#define O_CREAT 0x0040
// create the file if it does not exist
20
#define O_EXCL 0x0080
// with O_CREAT: fail if it exists
21
#define O_TRUNC 0x0200
// truncate a regular file opened for writing
22
#define O_APPEND 0x0400
// every write goes to the end of the file
23
#define O_NONBLOCK 0x0800
// return EAGAIN instead of waiting (pipes)
24
#define O_DIRECTORY 0x10000
// fail with ENOTDIR unless it is a directory
25
#define O_CLOEXEC 0x80000
// close the descriptor on execve
26
27
// the *at calls: a relative path is in the directory open as dirfd, or
28
// with AT_FDCWD in the working directory
29
#define AT_FDCWD (-100)
30
#define AT_SYMLINK_NOFOLLOW 0x100
// the link itself, not what it points at
31
#define AT_REMOVEDIR 0x200
// unlinkat: remove a directory
32
#define AT_SYMLINK_FOLLOW 0x400
// linkat: link to what a link points at
33
#define AT_EACCESS 0x200
// faccessat: check with the effective ids
34
35
int
openat
(
int
dirfd
,
const
char
*path,
int
flags
, ...);
36
37
// fcntl commands
38
#define F_DUPFD 0
// duplicate to the lowest free fd >= arg
39
#define F_GETFD 1
// get the descriptor flags
40
#define F_SETFD 2
// set the descriptor flags
41
#define F_GETFL 3
// get the status flags and access mode
42
#define F_SETFL 4
// set O_APPEND and O_NONBLOCK
43
#define F_DUPFD_CLOEXEC 1030
// F_DUPFD with FD_CLOEXEC set
44
45
// descriptor flags
46
#define FD_CLOEXEC 1
47
48
/**
49
* control an open file descriptor.
50
* @param fd the descriptor.
51
* @param cmd an F_ command.
52
* @param ... the command's int argument, if it takes one.
53
* @return the command's result, or -1 (errno set).
54
*/
55
int
fcntl
(
int
fd,
int
cmd, ...);
56
57
/**
58
* open a file.
59
* @param path the file's path.
60
* @param flags one access mode, plus creation and status flags.
61
* @param ... with O_CREAT, the mode_t for a new file.
62
* @return the lowest free file descriptor, or -1 (errno set).
63
*/
64
int
open
(
const
char
*path,
int
flags
, ...);
65
66
/**
67
* create a file, or truncate it if it exists, and open it for writing:
68
* open(path, O_WRONLY | O_CREAT | O_TRUNC, mode).
69
* @return a file descriptor, or -1 (errno set).
70
*/
71
int
creat
(
const
char
*path,
mode_t
mode);
openat
int openat(int dirfd, const char *path, int flags,...)
fcntl
int fcntl(int fd, int cmd,...)
control an open file descriptor.
open
int open(const char *path, int flags,...)
open a file.
creat
int creat(const char *path, mode_t mode)
create a file, or truncate it if it exists, and open it for writing: open(path, O_WRONLY | O_CREAT | ...
flags
uint8_t flags
Definition
idt.c:3
dirfd
int dirfd(DIR *dir)
the file descriptor under a directory stream.
types.h
basic system types.
mode_t
unsigned int mode_t
Definition
types.h:19
src
libc
include
fcntl.h
Generated by
1.18.0