Broken header dirent.h

Ryan Johnson ryan.johnson@cs.utoronto.ca
Sat Jul 12 17:54:00 GMT 2014


Hi all,

Please CC me in replies, I'm no longer a list member.

I recently tried to use <sys/dirent.h> in a C++ program and got linker 
errors. Turns out the header is neither C++-aware (extern "C") nor 
cygwin-aware (_EXFUN).

The attached patch fixes the problem for me.

Regards,
Ryan

-------------- next part --------------
--- dirent.h.orig	2014-05-23 04:36:40.000000000 -0400
+++ dirent.h	2014-07-12 12:31:44.904628400 -0400
@@ -15,6 +15,10 @@
 #include <sys/types.h>
 #include <limits.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define __DIRENT_VERSION	2
 
 #ifndef __x86_64__
@@ -62,32 +66,32 @@
 #pragma pack(pop)
 #endif
 
-DIR *opendir (const char *);
-DIR *fdopendir (int);
-struct dirent *readdir (DIR *);
-int readdir_r (DIR * __restrict, struct dirent * __restrict,
-	       struct dirent ** __restrict);
-void rewinddir (DIR *);
-int closedir (DIR *);
+DIR *_EXFUN(opendir, (const char *));
+DIR *_EXFUN(fdopendir, (int));
+struct dirent *_EXFUN(readdir, (DIR *));
+int _EXFUN(readdir_r, (DIR * __restrict, struct dirent * __restrict,
+		       struct dirent ** __restrict));
+void _EXFUN(rewinddir, (DIR *));
+int _EXFUN(closedir, (DIR *));
 
-int dirfd (DIR *);
+int _EXFUN(dirfd, (DIR *));
 
 #ifndef _POSIX_SOURCE
 #ifndef __INSIDE_CYGWIN__
-long telldir (DIR *);
-void seekdir (DIR *, long loc);
+long _EXFUN(telldir, (DIR *));
+void _EXFUN(seekdir, (DIR *, long loc));
 #endif
 
-int scandir (const char *__dir,
+int _EXFUN(scandir, (const char *__dir,
 	     struct dirent ***__namelist,
 	     int (*select) (const struct dirent *),
-	     int (*compar) (const struct dirent **, const struct dirent **));
+	     int (*compar) (const struct dirent **, const struct dirent **)));
 
-int scandirat (int __dirfd, const char *__dir, struct dirent ***__namelist,
+int _EXFUN(scandirat, (int __dirfd, const char *__dir, struct dirent ***__namelist,
 	       int (*select) (const struct dirent *),
-	       int (*compar) (const struct dirent **, const struct dirent **));
+	       int (*compar) (const struct dirent **, const struct dirent **)));
 
-int alphasort (const struct dirent **__a, const struct dirent **__b);
+int _EXFUN(alphasort, (const struct dirent **__a, const struct dirent **__b));
 #ifdef _DIRENT_HAVE_D_TYPE
 /* File types for `d_type'.  */
 enum
@@ -117,4 +121,8 @@
 # define DTTOIF(dirtype)        ((dirtype) << 12)
 #endif /* _DIRENT_HAVE_D_TYPE */
 #endif /* _POSIX_SOURCE */
+
+#ifdef __cplusplus
+}
+#endif
 #endif /*_SYS_DIRENT_H*/


More information about the Cygwin-developers mailing list