{"id":3852,"date":"2025-09-04T10:06:15","date_gmt":"2025-09-04T09:06:15","guid":{"rendered":"https:\/\/workboot.fr\/ciela\/?page_id=3852"},"modified":"2025-09-05T10:55:20","modified_gmt":"2025-09-05T09:55:20","slug":"open-close","status":"publish","type":"page","link":"https:\/\/workboot.fr\/ciela\/open-close\/","title":{"rendered":"open\/close"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Ces 2 fonctions sont intrins\u00e8quement li\u00e9es<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Si on ouvre un fichier , il faudra forc\u00e9ment le fermer dans votre code. Des codeurs n\u00e9gligeant omette de le faire mais cela prouve qu&rsquo;ils sont juste m\u00e9diocre.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">un fichier est une s\u00e9quence de donn\u00e9es , ici plus particuli\u00e8rement des octets .<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On va utiliser aussi les fonctions write et read , qui veulent dire \u00e9crire et lire <\/p>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><strong>man open<\/strong><\/summary>\n<p class=\"wp-block-paragraph\">open(2) \u2014 Linux manual page<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#NAME\">NAME<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#LIBRARY\">LIBRARY<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#SYNOPSIS\">SYNOPSIS<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#DESCRIPTION\">DESCRIPTION<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#RETURN_VALUE\">RETURN&nbsp;VALUE<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#ERRORS\">ERRORS<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#VERSIONS\">VERSIONS<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#STANDARDS\">STANDARDS<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#HISTORY\">HISTORY<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#NOTES\">NOTES<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#BUGS\">BUGS<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#SEE_ALSO\">SEE&nbsp;ALSO<\/a>&nbsp;|&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#COLOPHON\">COLOPHON<\/a><\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">&nbsp;<\/td><td><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong><em>open<\/em>(2)                    System Calls Manual                    <em>open<\/em>(2)<\/strong>\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#NAME\"><\/a>NAME &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       open, openat, creat - open and possibly create a file\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#LIBRARY\"><\/a>LIBRARY &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       Standard C library (<em>libc<\/em>, <em>-lc<\/em>)\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#SYNOPSIS\"><\/a>SYNOPSIS &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       <strong>#include &lt;fcntl.h&gt;<\/strong>\n\n       <strong>int open(const char *<\/strong><em>pathname<\/em><strong>, int <\/strong><em>flags<\/em><strong>, ...<\/strong>\n                  \/* <strong>mode_t <\/strong><em>mode<\/em> *\/ <strong>);<\/strong>\n\n       <strong>int creat(const char *<\/strong><em>pathname<\/em><strong>, mode_t <\/strong><em>mode<\/em><strong>);<\/strong>\n\n       <strong>int openat(int <\/strong><em>dirfd<\/em><strong>, const char *<\/strong><em>pathname<\/em><strong>, int <\/strong><em>flags<\/em><strong>, ...<\/strong>\n                  \/* <strong>mode_t <\/strong><em>mode<\/em> *\/ <strong>);<\/strong>\n\n       \/* Documented separately, in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat2.2.html\">openat2(2)<\/a>: *\/\n       <strong>int openat2(int <\/strong><em>dirfd<\/em><strong>, const char *<\/strong><em>pathname<\/em><strong>,<\/strong>\n                  <strong>const struct open_how *<\/strong><em>how<\/em><strong>, size_t <\/strong><em>size<\/em><strong>);<\/strong>\n\n   Feature Test Macro Requirements for glibc (see\n   <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/feature_test_macros.7.html\">feature_test_macros(7)<\/a>):\n\n       <strong>openat<\/strong>():\n           Since glibc 2.10:\n               _POSIX_C_SOURCE &gt;= 200809L\n           Before glibc 2.10:\n               _ATFILE_SOURCE\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#DESCRIPTION\"><\/a>DESCRIPTION &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       The <strong>open<\/strong>() system call opens the file specified by <em>pathname<\/em>.  If\n       the specified file does not exist, it may optionally (if <strong>O_CREAT<\/strong>\n       is specified in <em>flags<\/em>) be created by <strong>open<\/strong>().\n\n       The return value of <strong>open<\/strong>() is a file descriptor, a small,\n       nonnegative integer that is an index to an entry in the process's\n       table of open file descriptors.  The file descriptor is used in\n       subsequent system calls (<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/read.2.html\">read(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/lseek.2.html\">lseek(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>,\n       etc.)  to refer to the open file.  The file descriptor returned by\n       a successful call will be the lowest-numbered file descriptor not\n       currently open for the process.\n\n       By default, the new file descriptor is set to remain open across\n       an <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/execve.2.html\">execve(2)<\/a> (i.e., the <strong>FD_CLOEXEC <\/strong>file descriptor flag described\n       in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a> is initially disabled); the <strong>O_CLOEXEC <\/strong>flag, described\n       below, can be used to change this default.  The file offset is set\n       to the beginning of the file (see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/lseek.2.html\">lseek(2)<\/a>).\n\n       A call to <strong>open<\/strong>() creates a new <em>open file description<\/em>, an entry in\n       the system-wide table of open files.  The open file description\n       records the file offset and the file status flags (see below).  A\n       file descriptor is a reference to an open file description; this\n       reference is unaffected if <em>pathname<\/em> is subsequently removed or\n       modified to refer to a different file.  For further details on\n       open file descriptions, see NOTES.\n\n       The argument <em>flags<\/em> must include one of the following <em>access modes<\/em>:\n       <strong>O_RDONLY<\/strong>, <strong>O_WRONLY<\/strong>, or <strong>O_RDWR<\/strong>.  These request opening the file\n       read-only, write-only, or read\/write, respectively.\n\n       In addition, zero or more file creation flags and file status\n       flags can be bitwise ORed in <em>flags<\/em>.  The <em>file creation flags<\/em> are\n       <strong>O_CLOEXEC<\/strong>, <strong>O_CREAT<\/strong>, <strong>O_DIRECTORY<\/strong>, <strong>O_EXCL<\/strong>, <strong>O_NOCTTY<\/strong>, <strong>O_NOFOLLOW<\/strong>,\n       <strong>O_TMPFILE<\/strong>, and <strong>O_TRUNC<\/strong>.  The <em>file status flags<\/em> are all of the\n       remaining flags listed below.  The distinction between these two\n       groups of flags is that the file creation flags affect the\n       semantics of the open operation itself, while the file status\n       flags affect the semantics of subsequent I\/O operations.  The file\n       status flags can be retrieved and (in some cases) modified; see\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a> for details.\n\n       The full list of file creation flags and file status flags is as\n       follows:\n\n       <strong>O_APPEND<\/strong>\n              The file is opened in append mode.  Before each <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a>,\n              the file offset is positioned at the end of the file, as if\n              with <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/lseek.2.html\">lseek(2)<\/a>.  The modification of the file offset and the\n              write operation are performed as a single atomic step.\n\n              <strong>O_APPEND <\/strong>may lead to corrupted files on NFS filesystems if\n              more than one process appends data to a file at once.  This\n              is because NFS does not support appending to a file, so the\n              client kernel has to simulate it, which can't be done\n              without a race condition.\n\n       <strong>O_ASYNC<\/strong>\n              Enable signal-driven I\/O: generate a signal (<strong>SIGIO <\/strong>by\n              default, but this can be changed via <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>) when input\n              or output becomes possible on this file descriptor.  This\n              feature is available only for terminals, pseudoterminals,\n              sockets, and (since Linux 2.6) pipes and FIFOs.  See\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a> for further details.  See also BUGS, below.\n\n       <strong>O_CLOEXEC <\/strong>(since Linux 2.6.23)\n              Enable the close-on-exec flag for the new file descriptor.\n              Specifying this flag permits a program to avoid additional\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a> <strong>F_SETFD <\/strong>operations to set the <strong>FD_CLOEXEC <\/strong>flag.\n\n              Note that the use of this flag is essential in some\n              multithreaded programs, because using a separate <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>\n              <strong>F_SETFD <\/strong>operation to set the <strong>FD_CLOEXEC <\/strong>flag does not\n              suffice to avoid race conditions where one thread opens a\n              file descriptor and attempts to set its close-on-exec flag\n              using <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a> at the same time as another thread does a\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fork.2.html\">fork(2)<\/a> plus <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/execve.2.html\">execve(2)<\/a>.  Depending on the order of\n              execution, the race may lead to the file descriptor\n              returned by <strong>open<\/strong>() being unintentionally leaked to the\n              program executed by the child process created by <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fork.2.html\">fork(2)<\/a>.\n              (This kind of race is in principle possible for any system\n              call that creates a file descriptor whose close-on-exec\n              flag should be set, and various other Linux system calls\n              provide an equivalent of the <strong>O_CLOEXEC <\/strong>flag to deal with\n              this problem.)\n\n       <strong>O_CREAT<\/strong>\n              If <em>pathname<\/em> does not exist, create it as a regular file.\n\n              The owner (user ID) of the new file is set to the effective\n              user ID of the process.\n\n              The group ownership (group ID) of the new file is set\n              either to the effective group ID of the process (System V\n              semantics) or to the group ID of the parent directory (BSD\n              semantics).  On Linux, the behavior depends on whether the\n              set-group-ID mode bit is set on the parent directory: if\n              that bit is set, then BSD semantics apply; otherwise,\n              System V semantics apply.  For some filesystems, the\n              behavior also depends on the <em>bsdgroups<\/em> and <em>sysvgroups<\/em> mount\n              options described in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man8\/mount.8.html\">mount(8)<\/a>.\n\n              The <em>mode<\/em> argument specifies the file mode bits to be\n              applied when a new file is created.  If neither <strong>O_CREAT <\/strong>nor\n              <strong>O_TMPFILE <\/strong>is specified in <em>flags<\/em>, then <em>mode<\/em> is ignored (and\n              can thus be specified as 0, or simply omitted).  The <em>mode<\/em>\n              argument <strong>must <\/strong>be supplied if <strong>O_CREAT <\/strong>or <strong>O_TMPFILE <\/strong>is\n              specified in <em>flags<\/em>; if it is not supplied, some arbitrary\n              bytes from the stack will be applied as the file mode.\n\n              The effective mode is modified by the process's <em>umask<\/em> in\n              the usual way: in the absence of a default ACL, the mode of\n              the created file is <em>(mode &amp; ~umask)<\/em>.\n\n              Note that <em>mode<\/em> applies only to future accesses of the newly\n              created file; the <strong>open<\/strong>() call that creates a read-only file\n              may well return a read\/write file descriptor.\n\n              The following symbolic constants are provided for <em>mode<\/em>:\n\n              <strong>S_IRWXU  <\/strong>00700 user (file owner) has read, write, and\n                       execute permission\n\n              <strong>S_IRUSR  <\/strong>00400 user has read permission\n\n              <strong>S_IWUSR  <\/strong>00200 user has write permission\n\n              <strong>S_IXUSR  <\/strong>00100 user has execute permission\n\n              <strong>S_IRWXG  <\/strong>00070 group has read, write, and execute\n                       permission\n\n              <strong>S_IRGRP  <\/strong>00040 group has read permission\n\n              <strong>S_IWGRP  <\/strong>00020 group has write permission\n\n              <strong>S_IXGRP  <\/strong>00010 group has execute permission\n\n              <strong>S_IRWXO  <\/strong>00007 others have read, write, and execute\n                       permission\n\n              <strong>S_IROTH  <\/strong>00004 others have read permission\n\n              <strong>S_IWOTH  <\/strong>00002 others have write permission\n\n              <strong>S_IXOTH  <\/strong>00001 others have execute permission\n\n              According to POSIX, the effect when other bits are set in\n              <em>mode<\/em> is unspecified.  On Linux, the following bits are also\n              honored in <em>mode<\/em>:\n\n              <strong>S_ISUID  <\/strong>0004000 set-user-ID bit\n\n              <strong>S_ISGID  <\/strong>0002000 set-group-ID bit (see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/inode.7.html\">inode(7)<\/a>).\n\n              <strong>S_ISVTX  <\/strong>0001000 sticky bit (see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/inode.7.html\">inode(7)<\/a>).\n\n       <strong>O_DIRECT <\/strong>(since Linux 2.4.10)\n              Try to minimize cache effects of the I\/O to and from this\n              file.  In general this will degrade performance, but it is\n              useful in special situations, such as when applications do\n              their own caching.  File I\/O is done directly to\/from user-\n              space buffers.  The <strong>O_DIRECT <\/strong>flag on its own makes an\n              effort to transfer data synchronously, but does not give\n              the guarantees of the <strong>O_SYNC <\/strong>flag that data and necessary\n              metadata are transferred.  To guarantee synchronous I\/O,\n              <strong>O_SYNC <\/strong>must be used in addition to <strong>O_DIRECT<\/strong>.  See NOTES\n              below for further discussion.\n\n              A semantically similar (but deprecated) interface for block\n              devices is described in <strong>raw<\/strong>(8).\n\n       <strong>O_DIRECTORY<\/strong>\n              If <em>pathname<\/em> is not a directory, cause the open to fail.\n              This flag was added in Linux 2.1.126, to avoid denial-of-\n              service problems if <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/opendir.3.html\">opendir(3)<\/a> is called on a FIFO or tape\n              device.\n\n       <strong>O_DSYNC<\/strong>\n              Write operations on the file will complete according to the\n              requirements of synchronized I\/O <em>data<\/em> integrity completion.\n\n              By the time <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a> (and similar) return, the output data\n              has been transferred to the underlying hardware, along with\n              any file metadata that would be required to retrieve that\n              data (i.e., as though each <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a> was followed by a call\n              to <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fdatasync.2.html\">fdatasync(2)<\/a>).  See VERSIONS.\n\n       <strong>O_EXCL <\/strong>Ensure that this call creates the file: if this flag is\n              specified in conjunction with <strong>O_CREAT<\/strong>, and <em>pathname<\/em> already\n              exists, then <strong>open<\/strong>() fails with the error <strong>EEXIST<\/strong>.\n\n              When these two flags are specified, symbolic links are not\n              followed: if <em>pathname<\/em> is a symbolic link, then <strong>open<\/strong>() fails\n              regardless of where the symbolic link points.\n\n              In general, the behavior of <strong>O_EXCL <\/strong>is undefined if it is\n              used without <strong>O_CREAT<\/strong>.  There is one exception: on Linux 2.6\n              and later, <strong>O_EXCL <\/strong>can be used without <strong>O_CREAT <\/strong>if <em>pathname<\/em>\n              refers to a block device.  If the block device is in use by\n              the system (e.g., mounted), <strong>open<\/strong>() fails with the error\n              <strong>EBUSY<\/strong>.\n\n              On NFS, <strong>O_EXCL <\/strong>is supported only when using NFSv3 or later\n              on kernel 2.6 or later.  In NFS environments where <strong>O_EXCL<\/strong>\n              support is not provided, programs that rely on it for\n              performing locking tasks will contain a race condition.\n              Portable programs that want to perform atomic file locking\n              using a lockfile, and need to avoid reliance on NFS support\n              for <strong>O_EXCL<\/strong>, can create a unique file on the same filesystem\n              (e.g., incorporating hostname and PID), and use <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/link.2.html\">link(2)<\/a> to\n              make a link to the lockfile.  If <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/link.2.html\">link(2)<\/a> returns 0, the\n              lock is successful.  Otherwise, use <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/stat.2.html\">stat(2)<\/a> on the unique\n              file to check if its link count has increased to 2, in\n              which case the lock is also successful.\n\n       <strong>O_LARGEFILE<\/strong>\n              (LFS) Allow files whose sizes cannot be represented in an\n              <em>off_t<\/em> (but can be represented in an <em>off64_t<\/em>) to be opened.\n              The <strong>_LARGEFILE64_SOURCE <\/strong>macro must be defined (before\n              including <em>any<\/em> header files) in order to obtain this\n              definition.  Setting the <strong>_FILE_OFFSET_BITS <\/strong>feature test\n              macro to 64 (rather than using <strong>O_LARGEFILE<\/strong>) is the\n              preferred method of accessing large files on 32-bit systems\n              (see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/feature_test_macros.7.html\">feature_test_macros(7)<\/a>).\n\n       <strong>O_NOATIME <\/strong>(since Linux 2.6.8)\n              Do not update the file last access time (<em>st_atime<\/em> in the\n              inode) when the file is <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/read.2.html\">read(2)<\/a>.\n\n              This flag can be employed only if one of the following\n              conditions is true:\n\n              \u2022  The effective UID of the process matches the owner UID\n                 of the file.\n\n              \u2022  The calling process has the <strong>CAP_FOWNER <\/strong>capability in its\n                 user namespace and the owner UID of the file has a\n                 mapping in the namespace.\n\n              This flag is intended for use by indexing or backup\n              programs, where its use can significantly reduce the amount\n              of disk activity.  This flag may not be effective on all\n              filesystems.  One example is NFS, where the server\n              maintains the access time.\n\n       <strong>O_NOCTTY<\/strong>\n              If <em>pathname<\/em> refers to a terminal device\u2014see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man4\/tty.4.html\">tty(4)<\/a>\u2014it will\n              not become the process's controlling terminal even if the\n              process does not have one.\n\n       <strong>O_NOFOLLOW<\/strong>\n              If the trailing component (i.e., basename) of <em>pathname<\/em> is a\n              symbolic link, then the open fails, with the error <strong>ELOOP<\/strong>.\n              Symbolic links in earlier components of the pathname will\n              still be followed.  (Note that the <strong>ELOOP <\/strong>error that can\n              occur in this case is indistinguishable from the case where\n              an open fails because there are too many symbolic links\n              found while resolving components in the prefix part of the\n              pathname.)\n\n              This flag is a FreeBSD extension, which was added in Linux\n              2.1.126, and has subsequently been standardized in\n              POSIX.1-2008.\n\n              See also <strong>O_PATH <\/strong>below.\n\n       <strong>O_NONBLOCK <\/strong>or <strong>O_NDELAY<\/strong>\n              When possible, the file is opened in nonblocking mode.\n              Neither the <strong>open<\/strong>() nor any subsequent I\/O operations on the\n              file descriptor which is returned will cause the calling\n              process to wait.\n\n              Note that the setting of this flag has no effect on the\n              operation of <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/poll.2.html\">poll(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/select.2.html\">select(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/epoll.7.html\">epoll(7)<\/a>, and similar,\n              since those interfaces merely inform the caller about\n              whether a file descriptor is \"ready\", meaning that an I\/O\n              operation performed on the file descriptor with the\n              <strong>O_NONBLOCK <\/strong>flag <em>clear<\/em> would not block.\n\n              Note that this flag has no effect for regular files and\n              block devices; that is, I\/O operations will (briefly) block\n              when device activity is required, regardless of whether\n              <strong>O_NONBLOCK <\/strong>is set.  Since <strong>O_NONBLOCK <\/strong>semantics might\n              eventually be implemented, applications should not depend\n              upon blocking behavior when specifying this flag for\n              regular files and block devices.\n\n              For the handling of FIFOs (named pipes), see also <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/fifo.7.html\">fifo(7)<\/a>.\n              For a discussion of the effect of <strong>O_NONBLOCK <\/strong>in conjunction\n              with mandatory file locks and with file leases, see\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>.\n\n       <strong>O_PATH <\/strong>(since Linux 2.6.39)\n              Obtain a file descriptor that can be used for two purposes:\n              to indicate a location in the filesystem tree and to\n              perform operations that act purely at the file descriptor\n              level.  The file itself is not opened, and other file\n              operations (e.g., <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/read.2.html\">read(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchmod.2.html\">fchmod(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchown.2.html\">fchown(2)<\/a>,\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fgetxattr.2.html\">fgetxattr(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/ioctl.2.html\">ioctl(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mmap.2.html\">mmap(2)<\/a>) fail with the error <strong>EBADF<\/strong>.\n\n              The following operations <em>can<\/em> be performed on the resulting\n              file descriptor:\n\n              \u2022  <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/close.2.html\">close(2)<\/a>.\n\n              \u2022  <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchdir.2.html\">fchdir(2)<\/a>, if the file descriptor refers to a directory\n                 (since Linux 3.5).\n\n              \u2022  <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fstat.2.html\">fstat(2)<\/a> (since Linux 3.6).\n\n              \u2022  <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fstatfs.2.html\">fstatfs(2)<\/a> (since Linux 3.12).\n\n              \u2022  Duplicating the file descriptor (<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/dup.2.html\">dup(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>\n                 <strong>F_DUPFD<\/strong>, etc.).\n\n              \u2022  Getting and setting file descriptor flags (<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>\n                 <strong>F_GETFD <\/strong>and <strong>F_SETFD<\/strong>).\n\n              \u2022  Retrieving open file status flags using the <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>\n                 <strong>F_GETFL <\/strong>operation: the returned flags will include the\n                 bit <strong>O_PATH<\/strong>.\n\n              \u2022  Passing the file descriptor as the <em>dirfd<\/em> argument of\n                 <strong>openat<\/strong>() and the other \"*at()\" system calls.  This\n                 includes <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/linkat.2.html\">linkat(2)<\/a> with <strong>AT_EMPTY_PATH <\/strong>(or via procfs\n                 using <strong>AT_SYMLINK_FOLLOW<\/strong>) even if the file is not a\n                 directory.\n\n              \u2022  Passing the file descriptor to another process via a\n                 UNIX domain socket (see <strong>SCM_RIGHTS <\/strong>in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/unix.7.html\">unix(7)<\/a>).\n\n              When <strong>O_PATH <\/strong>is specified in <em>flags<\/em>, flag bits other than\n              <strong>O_CLOEXEC<\/strong>, <strong>O_DIRECTORY<\/strong>, and <strong>O_NOFOLLOW <\/strong>are ignored.\n\n              Opening a file or directory with the <strong>O_PATH <\/strong>flag requires\n              no permissions on the object itself (but does require\n              execute permission on the directories in the path prefix).\n              Depending on the subsequent operation, a check for suitable\n              file permissions may be performed (e.g., <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchdir.2.html\">fchdir(2)<\/a> requires\n              execute permission on the directory referred to by its file\n              descriptor argument).  By contrast, obtaining a reference\n              to a filesystem object by opening it with the <strong>O_RDONLY <\/strong>flag\n              requires that the caller have read permission on the\n              object, even when the subsequent operation (e.g.,\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchdir.2.html\">fchdir(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fstat.2.html\">fstat(2)<\/a>) does not require read permission on\n              the object.\n\n              If <em>pathname<\/em> is a symbolic link and the <strong>O_NOFOLLOW <\/strong>flag is\n              also specified, then the call returns a file descriptor\n              referring to the symbolic link.  This file descriptor can\n              be used as the <em>dirfd<\/em> argument in calls to <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchownat.2.html\">fchownat(2)<\/a>,\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fstatat.2.html\">fstatat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/linkat.2.html\">linkat(2)<\/a>, and <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/readlinkat.2.html\">readlinkat(2)<\/a> with an empty\n              pathname to have the calls operate on the symbolic link.\n\n              If <em>pathname<\/em> refers to an automount point that has not yet\n              been triggered, so no other filesystem is mounted on it,\n              then the call returns a file descriptor referring to the\n              automount directory without triggering a mount.  <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fstatfs.2.html\">fstatfs(2)<\/a>\n              can then be used to determine if it is, in fact, an\n              untriggered automount point (<strong>.f_type ==<\/strong>\n              <strong>AUTOFS_SUPER_MAGIC<\/strong>).\n\n              One use of <strong>O_PATH <\/strong>for regular files is to provide the\n              equivalent of POSIX.1's <strong>O_EXEC <\/strong>functionality.  This permits\n              us to open a file for which we have execute permission but\n              not read permission, and then execute that file, with steps\n              something like the following:\n\n                  char buf[PATH_MAX];\n                  fd = open(\"some_prog\", O_PATH);\n                  snprintf(buf, PATH_MAX, \"\/proc\/self\/fd\/%d\", fd);\n                  execl(buf, \"some_prog\", (char *) NULL);\n\n              An <strong>O_PATH <\/strong>file descriptor can also be passed as the\n              argument of <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/fexecve.3.html\">fexecve(3)<\/a>.\n\n       <strong>O_SYNC <\/strong>Write operations on the file will complete according to the\n              requirements of synchronized I\/O <em>file<\/em> integrity completion\n              (by contrast with the synchronized I\/O <em>data<\/em> integrity\n              completion provided by <strong>O_DSYNC<\/strong>.)\n\n              By the time <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a> (or similar) returns, the output data\n              and associated file metadata have been transferred to the\n              underlying hardware (i.e., as though each <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a> was\n              followed by a call to <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fsync.2.html\">fsync(2)<\/a>).  See VERSIONS.\n\n       <strong>O_TMPFILE <\/strong>(since Linux 3.11)\n              Create an unnamed temporary regular file.  The <em>pathname<\/em>\n              argument specifies a directory; an unnamed inode will be\n              created in that directory's filesystem.  Anything written\n              to the resulting file will be lost when the last file\n              descriptor is closed, unless the file is given a name.\n\n              <strong>O_TMPFILE <\/strong>must be specified with one of <strong>O_RDWR <\/strong>or <strong>O_WRONLY<\/strong>\n              and, optionally, <strong>O_EXCL<\/strong>.  If <strong>O_EXCL <\/strong>is not specified, then\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/linkat.2.html\">linkat(2)<\/a> can be used to link the temporary file into the\n              filesystem, making it permanent, using code like the\n              following:\n\n                  char path[PATH_MAX];\n                  fd = open(\"\/path\/to\/dir\", O_TMPFILE | O_RDWR,\n                                          S_IRUSR | S_IWUSR);\n\n                  \/* File I\/O on 'fd'... *\/\n\n                  linkat(fd, \"\", AT_FDCWD, \"\/path\/for\/file\", AT_EMPTY_PATH);\n\n                  \/* If the caller doesn't have the CAP_DAC_READ_SEARCH\n                     capability (needed to use AT_EMPTY_PATH with linkat(2)),\n                     and there is a proc(5) filesystem mounted, then the\n                     linkat(2) call above can be replaced with:\n\n                  snprintf(path, PATH_MAX,  \"\/proc\/self\/fd\/%d\", fd);\n                  linkat(AT_FDCWD, path, AT_FDCWD, \"\/path\/for\/file\",\n                                          AT_SYMLINK_FOLLOW);\n                  *\/\n\n              In this case, the <strong>open<\/strong>() <em>mode<\/em> argument determines the file\n              permission mode, as with <strong>O_CREAT<\/strong>.\n\n              Specifying <strong>O_EXCL <\/strong>in conjunction with <strong>O_TMPFILE <\/strong>prevents a\n              temporary file from being linked into the filesystem in the\n              above manner.  (Note that the meaning of <strong>O_EXCL <\/strong>in this\n              case is different from the meaning of <strong>O_EXCL <\/strong>otherwise.)\n\n              There are two main use cases for <strong>O_TMPFILE<\/strong>:\n\n              \u2022  Improved <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/tmpfile.3.html\">tmpfile(3)<\/a> functionality: race-free creation of\n                 temporary files that (1) are automatically deleted when\n                 closed; (2) can never be reached via any pathname; (3)\n                 are not subject to symlink attacks; and (4) do not\n                 require the caller to devise unique names.\n\n              \u2022  Creating a file that is initially invisible, which is\n                 then populated with data and adjusted to have\n                 appropriate filesystem attributes (<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchown.2.html\">fchown(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchmod.2.html\">fchmod(2)<\/a>,\n                 <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fsetxattr.2.html\">fsetxattr(2)<\/a>, etc.)  before being atomically linked into\n                 the filesystem in a fully formed state (using <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/linkat.2.html\">linkat(2)<\/a>\n                 as described above).\n\n              <strong>O_TMPFILE <\/strong>requires support by the underlying filesystem;\n              only a subset of Linux filesystems provide that support.\n              In the initial implementation, support was provided in the\n              ext2, ext3, ext4, UDF, Minix, and tmpfs filesystems.\n              Support for other filesystems has subsequently been added\n              as follows: XFS (Linux 3.15); Btrfs (Linux 3.16); F2FS\n              (Linux 3.16); and ubifs (Linux 4.9)\n\n       <strong>O_TRUNC<\/strong>\n              If the file already exists and is a regular file and the\n              access mode allows writing (i.e., is <strong>O_RDWR <\/strong>or <strong>O_WRONLY<\/strong>) it\n              will be truncated to length 0.  If the file is a FIFO or\n              terminal device file, the <strong>O_TRUNC <\/strong>flag is ignored.\n              Otherwise, the effect of <strong>O_TRUNC <\/strong>is unspecified.\n\n   <strong>creat()<\/strong>\n       A call to <strong>creat<\/strong>() is equivalent to calling <strong>open<\/strong>() with <em>flags<\/em> equal\n       to <strong>O_CREAT|O_WRONLY|O_TRUNC<\/strong>.\n\n   <strong>openat()<\/strong>\n       The <strong>openat<\/strong>() system call operates in exactly the same way as\n       <strong>open<\/strong>(), except for the differences described here.\n\n       The <em>dirfd<\/em> argument is used in conjunction with the <em>pathname<\/em>\n       argument as follows:\n\n       \u2022  If the pathname given in <em>pathname<\/em> is absolute, then <em>dirfd<\/em> is\n          ignored.\n\n       \u2022  If the pathname given in <em>pathname<\/em> is relative and <em>dirfd<\/em> is the\n          special value <strong>AT_FDCWD<\/strong>, then <em>pathname<\/em> is interpreted relative\n          to the current working directory of the calling process (like\n          <strong>open<\/strong>()).\n\n       \u2022  If the pathname given in <em>pathname<\/em> is relative, then it is\n          interpreted relative to the directory referred to by the file\n          descriptor <em>dirfd<\/em> (rather than relative to the current working\n          directory of the calling process, as is done by <strong>open<\/strong>() for a\n          relative pathname).  In this case, <em>dirfd<\/em> must be a directory\n          that was opened for reading (<strong>O_RDONLY<\/strong>) or using the <strong>O_PATH<\/strong>\n          flag.\n\n       If the pathname given in <em>pathname<\/em> is relative, and <em>dirfd<\/em> is not a\n       valid file descriptor, an error (<strong>EBADF<\/strong>) results.  (Specifying an\n       invalid file descriptor number in <em>dirfd<\/em> can be used as a means to\n       ensure that <em>pathname<\/em> is absolute.)\n\n   <strong>openat2(2)<\/strong>\n       The <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat2.2.html\">openat2(2)<\/a> system call is an extension of <strong>openat<\/strong>(), and\n       provides a superset of the features of <strong>openat<\/strong>().  It is documented\n       separately, in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat2.2.html\">openat2(2)<\/a>.\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#RETURN_VALUE\"><\/a>RETURN VALUE &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       On success, <strong>open<\/strong>(), <strong>openat<\/strong>(), and <strong>creat<\/strong>() return the new file\n       descriptor (a nonnegative integer).  On error, -1 is returned and\n       <em><a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/errno.3.html\">errno<\/a><\/em> is set to indicate the error.\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#ERRORS\"><\/a>ERRORS &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       <strong>open<\/strong>(), <strong>openat<\/strong>(), and <strong>creat<\/strong>() can fail with the following errors:\n\n       <strong>EACCES <\/strong>The requested access to the file is not allowed, or search\n              permission is denied for one of the directories in the path\n              prefix of <em>pathname<\/em>, or the file did not exist yet and write\n              access to the parent directory is not allowed.  (See also\n              <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/path_resolution.7.html\">path_resolution(7)<\/a>.)\n\n       <strong>EACCES <\/strong>Where <strong>O_CREAT <\/strong>is specified, the <em>protected_fifos<\/em> or\n              <em>protected_regular<\/em> sysctl is enabled, the file already\n              exists and is a FIFO or regular file, the owner of the file\n              is neither the current user nor the owner of the containing\n              directory, and the containing directory is both world- or\n              group-writable and sticky.  For details, see the\n              descriptions of <em>\/proc\/sys\/fs\/protected_fifos<\/em> and\n              <em>\/proc\/sys\/fs\/protected_regular<\/em> in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man5\/proc_sys_fs.5.html\">proc_sys_fs(5)<\/a>.\n\n       <strong>EBADF  <\/strong>(<strong>openat<\/strong>()) <em>pathname<\/em> is relative but <em>dirfd<\/em> is neither\n              <strong>AT_FDCWD <\/strong>nor a valid file descriptor.\n\n       <strong>EBUSY  O_EXCL <\/strong>was specified in <em>flags<\/em> and <em>pathname<\/em> refers to a\n              block device that is in use by the system (e.g., it is\n              mounted).\n\n       <strong>EDQUOT <\/strong>Where <strong>O_CREAT <\/strong>is specified, the file does not exist, and\n              the user's quota of disk blocks or inodes on the filesystem\n              has been exhausted.\n\n       <strong>EEXIST <\/strong><em>pathname<\/em> already exists and <strong>O_CREAT <\/strong>and <strong>O_EXCL <\/strong>were used.\n\n       <strong>EFAULT <\/strong><em>pathname<\/em> points outside your accessible address space.\n\n       <strong>EFBIG  <\/strong>See <strong>EOVERFLOW<\/strong>.\n\n       <strong>EINTR  <\/strong>While blocked waiting to complete an open of a slow device\n              (e.g., a FIFO; see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/fifo.7.html\">fifo(7)<\/a>), the call was interrupted by a\n              signal handler; see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/signal.7.html\">signal(7)<\/a>.\n\n       <strong>EINVAL <\/strong>The filesystem does not support the <strong>O_DIRECT <\/strong>flag.  See\n              <strong>NOTES <\/strong>for more information.\n\n       <strong>EINVAL <\/strong>Invalid value in <em>flags<\/em>.\n\n       <strong>EINVAL O_TMPFILE <\/strong>was specified in <em>flags<\/em>, but neither <strong>O_WRONLY <\/strong>nor\n              <strong>O_RDWR <\/strong>was specified.\n\n       <strong>EINVAL O_CREAT <\/strong>was specified in <em>flags<\/em> and the final component\n              (\"basename\") of the new file's <em>pathname<\/em> is invalid (e.g.,\n              it contains characters not permitted by the underlying\n              filesystem).\n\n       <strong>EINVAL <\/strong>The final component (\"basename\") of <em>pathname<\/em> is invalid\n              (e.g., it contains characters not permitted by the\n              underlying filesystem).\n\n       <strong>EISDIR <\/strong><em>pathname<\/em> refers to a directory and the access requested\n              involved writing (that is, <strong>O_WRONLY <\/strong>or <strong>O_RDWR <\/strong>is set).\n\n       <strong>EISDIR <\/strong><em>pathname<\/em> refers to an existing directory, <strong>O_TMPFILE <\/strong>and one\n              of <strong>O_WRONLY <\/strong>or <strong>O_RDWR <\/strong>were specified in <em>flags<\/em>, but this\n              kernel version does not provide the <strong>O_TMPFILE<\/strong>\n              functionality.\n\n       <strong>ELOOP  <\/strong>Too many symbolic links were encountered in resolving\n              <em>pathname<\/em>.\n\n       <strong>ELOOP  <\/strong><em>pathname<\/em> was a symbolic link, and <em>flags<\/em> specified\n              <strong>O_NOFOLLOW <\/strong>but not <strong>O_PATH<\/strong>.\n\n       <strong>EMFILE <\/strong>The per-process limit on the number of open file\n              descriptors has been reached (see the description of\n              <strong>RLIMIT_NOFILE <\/strong>in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/getrlimit.2.html\">getrlimit(2)<\/a>).\n\n       <strong>ENAMETOOLONG<\/strong>\n              <em>pathname<\/em> was too long.\n\n       <strong>ENFILE <\/strong>The system-wide limit on the total number of open files has\n              been reached.\n\n       <strong>ENODEV <\/strong><em>pathname<\/em> refers to a device special file and no\n              corresponding device exists.  (This is a Linux kernel bug;\n              in this situation <strong>ENXIO <\/strong>must be returned.)\n\n       <strong>ENOENT O_CREAT <\/strong>is not set and the named file does not exist.\n\n       <strong>ENOENT <\/strong>A directory component in <em>pathname<\/em> does not exist or is a\n              dangling symbolic link.\n\n       <strong>ENOENT <\/strong><em>pathname<\/em> refers to a nonexistent directory, <strong>O_TMPFILE <\/strong>and\n              one of <strong>O_WRONLY <\/strong>or <strong>O_RDWR <\/strong>were specified in <em>flags<\/em>, but this\n              kernel version does not provide the <strong>O_TMPFILE<\/strong>\n              functionality.\n\n       <strong>ENOMEM <\/strong>The named file is a FIFO, but memory for the FIFO buffer\n              can't be allocated because the per-user hard limit on\n              memory allocation for pipes has been reached and the caller\n              is not privileged; see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/pipe.7.html\">pipe(7)<\/a>.\n\n       <strong>ENOMEM <\/strong>Insufficient kernel memory was available.\n\n       <strong>ENOSPC <\/strong><em>pathname<\/em> was to be created but the device containing\n              <em>pathname<\/em> has no room for the new file.\n\n       <strong>ENOTDIR<\/strong>\n              A component used as a directory in <em>pathname<\/em> is not, in\n              fact, a directory, or <strong>O_DIRECTORY <\/strong>was specified and\n              <em>pathname<\/em> was not a directory.\n\n       <strong>ENOTDIR<\/strong>\n              (<strong>openat<\/strong>()) <em>pathname<\/em> is a relative pathname and <em>dirfd<\/em> is a\n              file descriptor referring to a file other than a directory.\n\n       <strong>ENXIO  O_NONBLOCK <\/strong>| <strong>O_WRONLY <\/strong>is set, the named file is a FIFO, and\n              no process has the FIFO open for reading.\n\n       <strong>ENXIO  <\/strong>The file is a device special file and no corresponding\n              device exists.\n\n       <strong>ENXIO  <\/strong>The file is a UNIX domain socket.\n\n       <strong>EOPNOTSUPP<\/strong>\n              The filesystem containing <em>pathname<\/em> does not support\n              <strong>O_TMPFILE<\/strong>.\n\n       <strong>EOVERFLOW<\/strong>\n              <em>pathname<\/em> refers to a regular file that is too large to be\n              opened.  The usual scenario here is that an application\n              compiled on a 32-bit platform without\n              <em>-D_FILE_OFFSET_BITS=64<\/em> tried to open a file whose size\n              exceeds <em>(1&lt;&lt;31)-1<\/em> bytes; see also <strong>O_LARGEFILE <\/strong>above.  This\n              is the error specified by POSIX.1; before Linux 2.6.24,\n              Linux gave the error <strong>EFBIG <\/strong>for this case.\n\n       <strong>EPERM  <\/strong>The <strong>O_NOATIME <\/strong>flag was specified, but the effective user ID\n              of the caller did not match the owner of the file and the\n              caller was not privileged.\n\n       <strong>EPERM  <\/strong>The operation was prevented by a file seal; see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>.\n\n       <strong>EROFS  <\/strong><em>pathname<\/em> refers to a file on a read-only filesystem and\n              write access was requested.\n\n       <strong>ETXTBSY<\/strong>\n              <em>pathname<\/em> refers to an executable image which is currently\n              being executed and write access was requested.\n\n       <strong>ETXTBSY<\/strong>\n              <em>pathname<\/em> refers to a file that is currently in use as a\n              swap file, and the <strong>O_TRUNC <\/strong>flag was specified.\n\n       <strong>ETXTBSY<\/strong>\n              <em>pathname<\/em> refers to a file that is currently being read by\n              the kernel (e.g., for module\/firmware loading), and write\n              access was requested.\n\n       <strong>EWOULDBLOCK<\/strong>\n              The <strong>O_NONBLOCK <\/strong>flag was specified, and an incompatible\n              lease was held on the file (see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>).\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#VERSIONS\"><\/a>VERSIONS &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       The (undefined) effect of <strong>O_RDONLY | O_TRUNC <\/strong>varies among\n       implementations.  On many systems the file is actually truncated.\n\n   <strong>Synchronized I\/O<\/strong>\n       The POSIX.1-2008 \"synchronized I\/O\" option specifies different\n       variants of synchronized I\/O, and specifies the <strong>open<\/strong>() flags\n       <strong>O_SYNC<\/strong>, <strong>O_DSYNC<\/strong>, and <strong>O_RSYNC <\/strong>for controlling the behavior.\n       Regardless of whether an implementation supports this option, it\n       must at least support the use of <strong>O_SYNC <\/strong>for regular files.\n\n       Linux implements <strong>O_SYNC <\/strong>and <strong>O_DSYNC<\/strong>, but not <strong>O_RSYNC<\/strong>.  Somewhat\n       incorrectly, glibc defines <strong>O_RSYNC <\/strong>to have the same value as\n       <strong>O_SYNC<\/strong>.  (<strong>O_RSYNC <\/strong>is defined in the Linux header file\n       <em>&lt;asm\/fcntl.h&gt;<\/em> on HP PA-RISC, but it is not used.)\n\n       <strong>O_SYNC <\/strong>provides synchronized I\/O <em>file<\/em> integrity completion,\n       meaning write operations will flush data and all associated\n       metadata to the underlying hardware.  <strong>O_DSYNC <\/strong>provides\n       synchronized I\/O <em>data<\/em> integrity completion, meaning write\n       operations will flush data to the underlying hardware, but will\n       only flush metadata updates that are required to allow a\n       subsequent read operation to complete successfully.  Data\n       integrity completion can reduce the number of disk operations that\n       are required for applications that don't need the guarantees of\n       file integrity completion.\n\n       To understand the difference between the two types of completion,\n       consider two pieces of file metadata: the file last modification\n       timestamp (<em>st_mtime<\/em>) and the file length.  All write operations\n       will update the last file modification timestamp, but only writes\n       that add data to the end of the file will change the file length.\n       The last modification timestamp is not needed to ensure that a\n       read completes successfully, but the file length is.  Thus,\n       <strong>O_DSYNC <\/strong>would only guarantee to flush updates to the file length\n       metadata (whereas <strong>O_SYNC <\/strong>would also always flush the last\n       modification timestamp metadata).\n\n       Before Linux 2.6.33, Linux implemented only the <strong>O_SYNC <\/strong>flag for\n       <strong>open<\/strong>().  However, when that flag was specified, most filesystems\n       actually provided the equivalent of synchronized I\/O <em>data<\/em>\n       integrity completion (i.e., <strong>O_SYNC <\/strong>was actually implemented as the\n       equivalent of <strong>O_DSYNC<\/strong>).\n\n       Since Linux 2.6.33, proper <strong>O_SYNC <\/strong>support is provided.  However,\n       to ensure backward binary compatibility, <strong>O_DSYNC <\/strong>was defined with\n       the same value as the historical <strong>O_SYNC<\/strong>, and <strong>O_SYNC <\/strong>was defined as\n       a new (two-bit) flag value that includes the <strong>O_DSYNC <\/strong>flag value.\n       This ensures that applications compiled against new headers get at\n       least <strong>O_DSYNC <\/strong>semantics before Linux 2.6.33.\n\n   <strong>C library\/kernel differences<\/strong>\n       Since glibc 2.26, the glibc wrapper function for <strong>open<\/strong>() employs\n       the <strong>openat<\/strong>() system call, rather than the kernel's <strong>open<\/strong>() system\n       call.  For certain architectures, this is also true before glibc\n       2.26.\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#STANDARDS\"><\/a>STANDARDS &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       <strong>open<\/strong>()\n       <strong>creat<\/strong>()\n       <strong>openat<\/strong>()\n              POSIX.1-2008.\n\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat2.2.html\">openat2(2)<\/a> Linux.\n\n       The <strong>O_DIRECT<\/strong>, <strong>O_NOATIME<\/strong>, <strong>O_PATH<\/strong>, and <strong>O_TMPFILE <\/strong>flags are Linux-\n       specific.  One must define <strong>_GNU_SOURCE <\/strong>to obtain their\n       definitions.\n\n       The <strong>O_CLOEXEC<\/strong>, <strong>O_DIRECTORY<\/strong>, and <strong>O_NOFOLLOW <\/strong>flags are not specified\n       in POSIX.1-2001, but are specified in POSIX.1-2008.  Since glibc\n       2.12, one can obtain their definitions by defining either\n       <strong>_POSIX_C_SOURCE <\/strong>with a value greater than or equal to 200809L or\n       <strong>_XOPEN_SOURCE <\/strong>with a value greater than or equal to 700.  In glibc\n       2.11 and earlier, one obtains the definitions by defining\n       <strong>_GNU_SOURCE<\/strong>.\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#HISTORY\"><\/a>HISTORY &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       <strong>open<\/strong>()\n       <strong>creat<\/strong>()\n              SVr4, 4.3BSD, POSIX.1-2001.\n\n       <strong>openat<\/strong>()\n              POSIX.1-2008.  Linux 2.6.16, glibc 2.4.\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#NOTES\"><\/a>NOTES &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       Under Linux, the <strong>O_NONBLOCK <\/strong>flag is sometimes used in cases where\n       one wants to open but does not necessarily have the intention to\n       read or write.  For example, this may be used to open a device in\n       order to get a file descriptor for use with <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/ioctl.2.html\">ioctl(2)<\/a>.\n\n       Note that <strong>open<\/strong>() can open device special files, but <strong>creat<\/strong>() cannot\n       create them; use <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mknod.2.html\">mknod(2)<\/a> instead.\n\n       If the file is newly created, its <em>st_atime<\/em>, <em>st_ctime<\/em>, <em>st_mtime<\/em>\n       fields (respectively, time of last access, time of last status\n       change, and time of last modification; see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/stat.2.html\">stat(2)<\/a>) are set to the\n       current time, and so are the <em>st_ctime<\/em> and <em>st_mtime<\/em> fields of the\n       parent directory.  Otherwise, if the file is modified because of\n       the <strong>O_TRUNC <\/strong>flag, its <em>st_ctime<\/em> and <em>st_mtime<\/em> fields are set to the\n       current time.\n\n       The files in the <em>\/proc\/<\/em>pid<em>\/fd<\/em> directory show the open file\n       descriptors of the process with the PID <em>pid<\/em>.  The files in the\n       <em>\/proc\/<\/em>pid<em>\/fdinfo<\/em> directory show even more information about these\n       file descriptors.  See <a href=\"https:\/\/man7.org\/linux\/man-pages\/man5\/proc.5.html\">proc(5)<\/a> for further details of both of\n       these directories.\n\n       The Linux header file <strong>&lt;asm\/fcntl.h&gt; <\/strong>doesn't define <strong>O_ASYNC<\/strong>; the\n       (BSD-derived) <strong>FASYNC <\/strong>synonym is defined instead.\n\n   <strong>Open file descriptions<\/strong>\n       The term open file description is the one used by POSIX to refer\n       to the entries in the system-wide table of open files.  In other\n       contexts, this object is variously also called an \"open file\n       object\", a \"file handle\", an \"open file table entry\", or\u2014in\n       kernel-developer parlance\u2014a <em>struct file<\/em>.\n\n       When a file descriptor is duplicated (using <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/dup.2.html\">dup(2)<\/a> or similar),\n       the duplicate refers to the same open file description as the\n       original file descriptor, and the two file descriptors\n       consequently share the file offset and file status flags.  Such\n       sharing can also occur between processes: a child process created\n       via <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fork.2.html\">fork(2)<\/a> inherits duplicates of its parent's file descriptors,\n       and those duplicates refer to the same open file descriptions.\n\n       Each <strong>open<\/strong>() of a file creates a new open file description; thus,\n       there may be multiple open file descriptions corresponding to a\n       file inode.\n\n       On Linux, one can use the <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/kcmp.2.html\">kcmp(2)<\/a> <strong>KCMP_FILE <\/strong>operation to test\n       whether two file descriptors (in the same process or in two\n       different processes) refer to the same open file description.\n\n   <strong>NFS<\/strong>\n       There are many infelicities in the protocol underlying NFS,\n       affecting amongst others <strong>O_SYNC <\/strong>and <strong>O_NDELAY<\/strong>.\n\n       On NFS filesystems with UID mapping enabled, <strong>open<\/strong>() may return a\n       file descriptor but, for example, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/read.2.html\">read(2)<\/a> requests are denied with\n       <strong>EACCES<\/strong>.  This is because the client performs <strong>open<\/strong>() by checking\n       the permissions, but UID mapping is performed by the server upon\n       read and write requests.\n\n   <strong>FIFOs<\/strong>\n       Opening the read or write end of a FIFO blocks until the other end\n       is also opened (by another process or thread).  See <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/fifo.7.html\">fifo(7)<\/a> for\n       further details.\n\n   <strong>File access mode<\/strong>\n       Unlike the other values that can be specified in <em>flags<\/em>, the <em>access<\/em>\n       <em>mode<\/em> values <strong>O_RDONLY<\/strong>, <strong>O_WRONLY<\/strong>, and <strong>O_RDWR <\/strong>do not specify\n       individual bits.  Rather, they define the low order two bits of\n       <em>flags<\/em>, and are defined respectively as 0, 1, and 2.  In other\n       words, the combination <strong>O_RDONLY | O_WRONLY <\/strong>is a logical error, and\n       certainly does not have the same meaning as <strong>O_RDWR<\/strong>.\n\n       Linux reserves the special, nonstandard access mode 3 (binary 11)\n       in <em>flags<\/em> to mean: check for read and write permission on the file\n       and return a file descriptor that can't be used for reading or\n       writing.  This nonstandard access mode is used by some Linux\n       drivers to return a file descriptor that is to be used only for\n       device-specific <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/ioctl.2.html\">ioctl(2)<\/a> operations.\n\n   <strong>Rationale for openat() and other directory file descriptor APIs<\/strong>\n       <strong>openat<\/strong>() and the other system calls and library functions that\n       take a directory file descriptor argument (i.e., <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/execveat.2.html\">execveat(2)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/faccessat.2.html\">faccessat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fanotify_mark.2.html\">fanotify_mark(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchmodat.2.html\">fchmodat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fchownat.2.html\">fchownat(2)<\/a>,\n       <strong>fspick<\/strong>(2), <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fstatat.2.html\">fstatat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/futimesat.2.html\">futimesat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/linkat.2.html\">linkat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mkdirat.2.html\">mkdirat(2)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mknodat.2.html\">mknodat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mount_setattr.2.html\">mount_setattr(2)<\/a>, <strong>move_mount<\/strong>(2), <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/name_to_handle_at.2.html\">name_to_handle_at(2)<\/a>,\n       <strong>open_tree<\/strong>(2), <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat2.2.html\">openat2(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/readlinkat.2.html\">readlinkat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/renameat.2.html\">renameat(2)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/renameat2.2.html\">renameat2(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/statx.2.html\">statx(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/symlinkat.2.html\">symlinkat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/unlinkat.2.html\">unlinkat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/utimensat.2.html\">utimensat(2)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/mkfifoat.3.html\">mkfifoat(3)<\/a>, and <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/scandirat.3.html\">scandirat(3)<\/a>) address two problems with the older\n       interfaces that preceded them.  Here, the explanation is in terms\n       of the <strong>openat<\/strong>() call, but the rationale is analogous for the other\n       interfaces.\n\n       First, <strong>openat<\/strong>() allows an application to avoid race conditions\n       that could occur when using <strong>open<\/strong>() to open files in directories\n       other than the current working directory.  These race conditions\n       result from the fact that some component of the directory prefix\n       given to <strong>open<\/strong>() could be changed in parallel with the call to\n       <strong>open<\/strong>().  Suppose, for example, that we wish to create the file\n       <em>dir1\/dir2\/xxx.dep<\/em> if the file <em>dir1\/dir2\/xxx<\/em> exists.  The problem\n       is that between the existence check and the file-creation step,\n       <em>dir1<\/em> or <em>dir2<\/em> (which might be symbolic links) could be modified to\n       point to a different location.  Such races can be avoided by\n       opening a file descriptor for the target directory, and then\n       specifying that file descriptor as the <em>dirfd<\/em> argument of (say)\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fstatat.2.html\">fstatat(2)<\/a> and <strong>openat<\/strong>().  The use of the <em>dirfd<\/em> file descriptor\n       also has other benefits:\n\n       \u2022  the file descriptor is a stable reference to the directory,\n          even if the directory is renamed; and\n\n       \u2022  the open file descriptor prevents the underlying filesystem\n          from being dismounted, just as when a process has a current\n          working directory on a filesystem.\n\n       Second, <strong>openat<\/strong>() allows the implementation of a per-thread\n       \"current working directory\", via file descriptor(s) maintained by\n       the application.  (This functionality can also be obtained by\n       tricks based on the use of <em>\/proc\/self\/fd\/<\/em>dirfd, but less\n       efficiently.)\n\n       The <em>dirfd<\/em> argument for these APIs can be obtained by using <strong>open<\/strong>()\n       or <strong>openat<\/strong>() to open a directory (with either the <strong>O_RDONLY <\/strong>or the\n       <strong>O_PATH <\/strong>flag).  Alternatively, such a file descriptor can be\n       obtained by applying <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/dirfd.3.html\">dirfd(3)<\/a> to a directory stream created using\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/opendir.3.html\">opendir(3)<\/a>.\n\n       When these APIs are given a <em>dirfd<\/em> argument of <strong>AT_FDCWD <\/strong>or the\n       specified pathname is absolute, then they handle their pathname\n       argument in the same way as the corresponding conventional APIs.\n       However, in this case, several of the APIs have a <em>flags<\/em> argument\n       that provides access to functionality that is not available with\n       the corresponding conventional APIs.\n\n   <strong>O_DIRECT<\/strong>\n       The <strong>O_DIRECT <\/strong>flag may impose alignment restrictions on the length\n       and address of user-space buffers and the file offset of I\/Os.  In\n       Linux alignment restrictions vary by filesystem and kernel version\n       and might be absent entirely.  The handling of misaligned <strong>O_DIRECT<\/strong>\n       I\/Os also varies; they can either fail with <strong>EINVAL <\/strong>or fall back to\n       buffered I\/O.\n\n       Since Linux 6.1, <strong>O_DIRECT <\/strong>support and alignment restrictions for a\n       file can be queried using <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/statx.2.html\">statx(2)<\/a>, using the <strong>STATX_DIOALIGN <\/strong>flag.\n       Support for <strong>STATX_DIOALIGN <\/strong>varies by filesystem; see <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/statx.2.html\">statx(2)<\/a>.\n\n       Some filesystems provide their own interfaces for querying\n       <strong>O_DIRECT <\/strong>alignment restrictions, for example the <strong>XFS_IOC_DIOINFO<\/strong>\n       operation in <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/xfsctl.3.html\">xfsctl(3)<\/a>.  <strong>STATX_DIOALIGN <\/strong>should be used instead\n       when it is available.\n\n       If none of the above is available, then direct I\/O support and\n       alignment restrictions can only be assumed from known\n       characteristics of the filesystem, the individual file, the\n       underlying storage device(s), and the kernel version.  In Linux\n       2.4, most filesystems based on block devices require that the file\n       offset and the length and memory address of all I\/O segments be\n       multiples of the filesystem block size (typically 4096 bytes).  In\n       Linux 2.6.0, this was relaxed to the logical block size of the\n       block device (typically 512 bytes).  A block device's logical\n       block size can be determined using the <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/ioctl.2.html\">ioctl(2)<\/a> <strong>BLKSSZGET<\/strong>\n       operation or from the shell using the command:\n\n           blockdev --getss\n\n       <strong>O_DIRECT <\/strong>I\/Os should never be run concurrently with the <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fork.2.html\">fork(2)<\/a>\n       system call, if the memory buffer is a private mapping (i.e., any\n       mapping created with the <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mmap.2.html\">mmap(2)<\/a> <strong>MAP_PRIVATE <\/strong>flag; this includes\n       memory allocated on the heap and statically allocated buffers).\n       Any such I\/Os, whether submitted via an asynchronous I\/O interface\n       or from another thread in the process, should be completed before\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fork.2.html\">fork(2)<\/a> is called.  Failure to do so can result in data corruption\n       and undefined behavior in parent and child processes.  This\n       restriction does not apply when the memory buffer for the <strong>O_DIRECT<\/strong>\n       I\/Os was created using <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/shmat.2.html\">shmat(2)<\/a> or <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mmap.2.html\">mmap(2)<\/a> with the <strong>MAP_SHARED<\/strong>\n       flag.  Nor does this restriction apply when the memory buffer has\n       been advised as <strong>MADV_DONTFORK <\/strong>with <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/madvise.2.html\">madvise(2)<\/a>, ensuring that it\n       will not be available to the child after <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fork.2.html\">fork(2)<\/a>.\n\n       The <strong>O_DIRECT <\/strong>flag was introduced in SGI IRIX, where it has\n       alignment restrictions similar to those of Linux 2.4.  IRIX has\n       also a <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a> call to query appropriate alignments, and sizes.\n       FreeBSD 4.x introduced a flag of the same name, but without\n       alignment restrictions.\n\n       <strong>O_DIRECT <\/strong>support was added in Linux 2.4.10.  Older Linux kernels\n       simply ignore this flag.  Some filesystems may not implement the\n       flag, in which case <strong>open<\/strong>() fails with the error <strong>EINVAL <\/strong>if it is\n       used.\n\n       Applications should avoid mixing <strong>O_DIRECT <\/strong>and normal I\/O to the\n       same file, and especially to overlapping byte regions in the same\n       file.  Even when the filesystem correctly handles the coherency\n       issues in this situation, overall I\/O throughput is likely to be\n       slower than using either mode alone.  Likewise, applications\n       should avoid mixing <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mmap.2.html\">mmap(2)<\/a> of files with direct I\/O to the same\n       files.\n\n       The behavior of <strong>O_DIRECT <\/strong>with NFS will differ from local\n       filesystems.  Older kernels, or kernels configured in certain\n       ways, may not support this combination.  The NFS protocol does not\n       support passing the flag to the server, so <strong>O_DIRECT <\/strong>I\/O will\n       bypass the page cache only on the client; the server may still\n       cache the I\/O.  The client asks the server to make the I\/O\n       synchronous to preserve the synchronous semantics of <strong>O_DIRECT<\/strong>.\n       Some servers will perform poorly under these circumstances,\n       especially if the I\/O size is small.  Some servers may also be\n       configured to lie to clients about the I\/O having reached stable\n       storage; this will avoid the performance penalty at some risk to\n       data integrity in the event of server power failure.  The Linux\n       NFS client places no alignment restrictions on <strong>O_DIRECT <\/strong>I\/O.\n\n       In summary, <strong>O_DIRECT <\/strong>is a potentially powerful tool that should be\n       used with caution.  It is recommended that applications treat use\n       of <strong>O_DIRECT <\/strong>as a performance option which is disabled by default.\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#BUGS\"><\/a>BUGS &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">       Currently, it is not possible to enable signal-driven I\/O by\n       specifying <strong>O_ASYNC <\/strong>when calling <strong>open<\/strong>(); use <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a> to enable\n       this flag.\n\n       One must check for two different error codes, <strong>EISDIR <\/strong>and <strong>ENOENT<\/strong>,\n       when trying to determine whether the kernel supports <strong>O_TMPFILE<\/strong>\n       functionality.\n\n       When both <strong>O_CREAT <\/strong>and <strong>O_DIRECTORY <\/strong>are specified in <em>flags<\/em> and the\n       file specified by <em>pathname<\/em> does not exist, <strong>open<\/strong>() will create a\n       regular file (i.e., <strong>O_DIRECTORY <\/strong>is ignored).\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#SEE_ALSO\"><\/a>SEE ALSO &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat.2.html#top_of_page\">top<\/a><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/chmod.2.html\">chmod(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/chown.2.html\">chown(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/close.2.html\">close(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/dup.2.html\">dup(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/fcntl.2.html\">fcntl(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/link.2.html\">link(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/lseek.2.html\">lseek(2)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mknod.2.html\">mknod(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mmap.2.html\">mmap(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/mount.2.html\">mount(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/open_by_handle_at.2.html\">open_by_handle_at(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/openat2.2.html\">openat2(2)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/read.2.html\">read(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/socket.2.html\">socket(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/stat.2.html\">stat(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/umask.2.html\">umask(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/unlink.2.html\">unlink(2)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man2\/write.2.html\">write(2)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man3\/fopen.3.html\">fopen(3)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man5\/acl.5.html\">acl(5)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/fifo.7.html\">fifo(7)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/inode.7.html\">inode(7)<\/a>, <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/path_resolution.7.html\">path_resolution(7)<\/a>,\n       <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/symlink.7.html\">symlink(7)<\/a><\/p>\n<\/details>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"h.uvylikrht2p7_l\">Ecriture :&nbsp;<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Exemple simple de cr\u00e9ation d&rsquo;un fichier texte en lecture \u00e9criture uniquement par le propri\u00e9taire<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/* exemple simple avec write *\/\n\n#include &lt;stdlib.h>\n#include &lt;stdio.h>\n#include &lt;sys\/stat.h>\n#include &lt;fcntl.h>\n#include &lt;unistd.h>\n\nint main (int argc, char ** argv)\n{\nint fd; \/* file desciptor *\/\nfd = open ( \"fichier.txt\",O_CREAT | O_RDWR \n                         ,S_IRUSR | S_IWUSR );  \/* droits Read USER Write USER...*\/\n\/* aller voir man 3 open *\/\nif (fd==-1)     \n              {\n              printf(\"Erreur d'ouverture du fichier \\n\");\n              return EXIT_FAILURE;\n              }\nwrite (fd, \"Bonjour le monde\\n\",17);  \/* 17 etant le nombre de caractere de la chaine *\/\nclose(fd);\nreturn EXIT_SUCCESS;\n\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ecrire un fichier en compliquant un peu&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">exemple 2 d\u2019\u00e9criture&nbsp;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/* exemple 2 avec une chaine *\/\n#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;termios.h>\n#include &lt;unistd.h>\n#include &lt;sys\/types.h>\n#include &lt;sys\/stat.h>\n#include &lt;fcntl.h>\n\nint main()\n{\n   int fd;\n   char chaine[100]=\"Bonjour le monda !\";\n   fd=open (\"\/tmp\/bonjour.txt\",O_CREAT | O_WRONLY,\n                        S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );\n   if (fd==-1)         {\n                       perror(\"Pas possible d'ouvrir ce fichier \");\n                       return EXIT_FAILURE;\n                       }\n   write(fd,chaine,16);\n   printf(\"%s\",chaine);\n   close (fd);\n   return EXIT_SUCCESS;\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Lire :<\/h2>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/*  Lecture de fichier *\/\n#include &lt;stdio.h>\n#include &lt;stdlib.h>\n#include &lt;termios.h>\n#include &lt;unistd.h>\n#include &lt;sys\/types.h>\n#include &lt;sys\/stat.h>\n#include &lt;fcntl.h>\n\nint main()\n{\n   int fd;\n   char chaine[100];\n   fd=open (\"fichier.txt\",O_CREAT | O_RDONLY,\n                        S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );\n   if (fd==-1)         {\n                       perror(\"Pas possible d'ouvrir ce fichier \");\n                       return EXIT_FAILURE;\n                       }\n   read(fd,chaine,16);\n   printf(\"%s\",chaine);\n   close (fd);\n   printf(\"Hello World!\\n\");\n   return EXIT_SUCCESS;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ces 2 fonctions sont intrins\u00e8quement li\u00e9es Si on ouvre un fichier , il faudra forc\u00e9ment le fermer dans votre code. Des codeurs n\u00e9gligeant omette de le faire mais cela prouve [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","_uag_custom_page_level_css":"","footnotes":""},"class_list":["post-3852","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>open\/close - workboot<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/workboot.fr\/ciela\/open-close\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"open\/close - workboot\" \/>\n<meta property=\"og:description\" content=\"Ces 2 fonctions sont intrins\u00e8quement li\u00e9es Si on ouvre un fichier , il faudra forc\u00e9ment le fermer dans votre code. Des codeurs n\u00e9gligeant omette de le faire mais cela prouve [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/workboot.fr\/ciela\/open-close\/\" \/>\n<meta property=\"og:site_name\" content=\"workboot\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-05T09:55:20+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/open-close\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/open-close\\\/\",\"name\":\"open\\\/close - workboot\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\"},\"datePublished\":\"2025-09-04T09:06:15+00:00\",\"dateModified\":\"2025-09-05T09:55:20+00:00\",\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/workboot.fr\\\/ciela\\\/open-close\\\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#website\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"name\":\"workboot\",\"description\":\"Open Source, Open Minds \",\"publisher\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#organization\",\"name\":\"workboot\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"contentUrl\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/logo_ciel-dorian-1.png\",\"width\":1024,\"height\":950,\"caption\":\"workboot\"},\"image\":{\"@id\":\"https:\\\/\\\/workboot.fr\\\/ciela\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"open\/close - workboot","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/workboot.fr\/ciela\/open-close\/","og_locale":"fr_FR","og_type":"article","og_title":"open\/close - workboot","og_description":"Ces 2 fonctions sont intrins\u00e8quement li\u00e9es Si on ouvre un fichier , il faudra forc\u00e9ment le fermer dans votre code. Des codeurs n\u00e9gligeant omette de le faire mais cela prouve [&hellip;]","og_url":"https:\/\/workboot.fr\/ciela\/open-close\/","og_site_name":"workboot","article_modified_time":"2025-09-05T09:55:20+00:00","twitter_misc":{"Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/workboot.fr\/ciela\/open-close\/","url":"https:\/\/workboot.fr\/ciela\/open-close\/","name":"open\/close - workboot","isPartOf":{"@id":"https:\/\/workboot.fr\/ciela\/#website"},"datePublished":"2025-09-04T09:06:15+00:00","dateModified":"2025-09-05T09:55:20+00:00","inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/workboot.fr\/ciela\/open-close\/"]}]},{"@type":"WebSite","@id":"https:\/\/workboot.fr\/ciela\/#website","url":"https:\/\/workboot.fr\/ciela\/","name":"workboot","description":"Open Source, Open Minds ","publisher":{"@id":"https:\/\/workboot.fr\/ciela\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/workboot.fr\/ciela\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/workboot.fr\/ciela\/#organization","name":"workboot","url":"https:\/\/workboot.fr\/ciela\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/","url":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","contentUrl":"https:\/\/workboot.fr\/ciela\/wp-content\/uploads\/2025\/05\/logo_ciel-dorian-1.png","width":1024,"height":950,"caption":"workboot"},"image":{"@id":"https:\/\/workboot.fr\/ciela\/#\/schema\/logo\/image\/"}}]}},"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"admin","author_link":"https:\/\/workboot.fr\/ciela\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Ces 2 fonctions sont intrins\u00e8quement li\u00e9es Si on ouvre un fichier , il faudra forc\u00e9ment le fermer dans votre code. Des codeurs n\u00e9gligeant omette de le faire mais cela prouve [&hellip;]","_links":{"self":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/comments?post=3852"}],"version-history":[{"count":7,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3852\/revisions"}],"predecessor-version":[{"id":3881,"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/pages\/3852\/revisions\/3881"}],"wp:attachment":[{"href":"https:\/\/workboot.fr\/ciela\/wp-json\/wp\/v2\/media?parent=3852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}