[PATCH v2 15/16] libelf: F_GETFD may not predefined with msvc/mingw, guard the usage of it

Yonggang Luo luoyonggang@gmail.com
Sat Dec 17 16:52:12 GMT 2022


Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 libelf/elf_begin.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index 6d31882e..3d324694 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -1163,12 +1163,19 @@ elf_begin (int fildes, Elf_Cmd cmd, Elf *ref)
   if (ref != NULL)
     /* Make sure the descriptor is not suddenly going away.  */
     rwlock_rdlock (ref->lock);
+#if defined(F_GETFD)
   else if (unlikely (fcntl (fildes, F_GETFD) == -1 && errno == EBADF))
     {
       /* We cannot do anything productive without a file descriptor.  */
       __libelf_seterrno (ELF_E_INVALID_FILE);
       return NULL;
     }
+#else
+  else if (fildes < 0)
+    {
+      return NULL;
+    }
+#endif
 
   switch (cmd)
     {
-- 
2.36.1.windows.1



More information about the Elfutils-devel mailing list