| @node open | |
| @subsection @code{open} | |
| @findex open | |
| POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9799919799/functions/open.html} | |
| Gnulib module: open, fchdir | |
| @mindex open | |
| @mindex fchdir | |
| Portability problems fixed by the Gnulib module @code{open}: | |
| @itemize | |
| @item | |
| Some platforms do not support @code{O_CLOEXEC}: | |
| @c See posix-headers/fcntl.texi for the list. | |
| Mac OS X 10.6, FreeBSD 8.4, NetBSD 5.1, OpenBSD 4.9, Minix 3.1.8, AIX 7.1, HP-UX 11, Solaris 10, Cygwin 1.7.x, mingw, MSVC 14. | |
| @item | |
| Some platforms do not support @code{O_DIRECTORY}: | |
| glibc 2.0, Mac OS X 10.4, FreeBSD 7.4, NetBSD 4.0.1, OpenBSD 4.9, HP-UX 11, Solaris 10, Cygwin 1.5.x, mingw, MSVC 14. | |
| @item | |
| On platforms where @code{off_t} is a 32-bit type, @code{open} may not work | |
| correctly with files 2 GiB and larger. @xref{Large File Support}. | |
| @item | |
| This function does not fail when the file name argument ends in a slash | |
| and (without the slash) names a nonexistent file or a file that is not a | |
| directory, on some platforms: | |
| macOS 14, FreeBSD 7.2, AIX 7.1, HP-UX 11.00, Solaris 9. | |
| @item | |
| @mindex nonblocking | |
| This function does not support the @code{O_NONBLOCK} flag when it is defined | |
| by the gnulib module @code{nonblocking} on some platforms: | |
| mingw, MSVC 14. | |
| @item | |
| On Windows platforms (excluding Cygwin), this function does usually not | |
| recognize the @file{/dev/null} filename. | |
| @end itemize | |
| Portability problems fixed by the Gnulib module @code{fchdir}: | |
| @itemize | |
| @item | |
| On Windows platforms (excluding Cygwin), this function fails to open a | |
| read-only descriptor for directories. | |
| @end itemize | |
| Portability problems not fixed by Gnulib: | |
| @itemize | |
| @item | |
| The Gnulib replacement for @code{O_CLOEXEC} is not atomic, and so is | |
| not safe in the presence of multiple threads or signal handlers. | |
| @item | |
| The Gnulib replacement for @code{O_SEARCH} may require read access | |
| instead of search/execute access. | |
| @item | |
| On some platforms, @code{O_SEARCH} may reject directories | |
| where you have search access even though @code{O_SEARCH} is not replaced: | |
| macOS 12.6. | |
| @item | |
| When the file does not exist, POSIX says | |
| the behavior of @code{O_CREAT | O_DIRECTORY} is unspecified. | |
| Most platforms fail with @code{EINVAL} in this case. | |
| However, in Linux kernels 6.3 and earlier, this function | |
| creates a regular file and then either returns successfully | |
| (Linux kernel 5.6 and earlier) or fails with @code{ENOTDIR} | |
| (Linux kernels 5.7--6.3). | |
| @item | |
| @code{open ("symlink", O_CREAT ...)} fails when the argument points to a | |
| nonexistent file in an existing directory on some platforms: | |
| @c https://dev.haiku-os.org/ticket/18355 | |
| Haiku. | |
| @item | |
| @code{open ("symlink", O_NOFOLLOW ...)} fails with @code{errno} set to | |
| @code{EMLINK} instead of the POSIX-required @code{ELOOP} on some | |
| platforms: | |
| FreeBSD 14.2. | |
| @item | |
| @code{open ("symlink", O_NOFOLLOW ...)} fails with @code{errno} set to | |
| @code{EFTYPE} instead of the POSIX-required @code{ELOOP} on some | |
| platforms: | |
| NetBSD 10.0. | |
| @item | |
| @code{open ("fifo", O_DIRECTORY ...)} does not fail on some platforms: | |
| @c https://dev.haiku-os.org/ticket/19879 | |
| Haiku. | |
| @item | |
| On Windows, this function returns a file handle in @code{O_TEXT} mode by | |
| default; this means that it translates @code{'\n'} to CR/LF by default. Use the | |
| @code{O_BINARY} flag if you need reliable binary I/O. | |
| @end itemize |