From 87c19cb11a8a6752cb1fb829d121b7425f4e8600 Mon Sep 17 00:00:00 2001 From: Alexander Senier Date: Mon, 3 Jul 2017 00:31:24 +0200 Subject: [PATCH] libc: handle O_CREAT|O_NOFOLLOW in open correctly We return ELOOP if the file already exists on open(...,O_CREAT|O_NOFOLLOW). Fixes #2458 --- repos/libports/src/lib/libc/vfs_plugin.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/repos/libports/src/lib/libc/vfs_plugin.cc b/repos/libports/src/lib/libc/vfs_plugin.cc index ad157a68ba..5acf6e582f 100644 --- a/repos/libports/src/lib/libc/vfs_plugin.cc +++ b/repos/libports/src/lib/libc/vfs_plugin.cc @@ -196,7 +196,12 @@ Libc::File_descriptor *Libc::Vfs_plugin::open(char const *path, int flags, case Result::OPEN_ERR_EXISTS: /* file has been created by someone else in the meantime */ - break; + if (flags & O_NOFOLLOW) { + errno = ELOOP; + return 0; + } + errno = EEXIST; + return 0; case Result::OPEN_ERR_NO_PERM: errno = EPERM; return 0; case Result::OPEN_ERR_UNACCESSIBLE: errno = ENOENT; return 0;