public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
* Broken header dirent.h
@ 2014-07-12 17:54 Ryan Johnson
  2014-07-14  8:49 ` Corinna Vinschen
  0 siblings, 1 reply; 3+ messages in thread
From: Ryan Johnson @ 2014-07-12 17:54 UTC (permalink / raw)
  To: cygwin-developers

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

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


[-- Attachment #2: dirent.h.patch --]
[-- Type: text/plain, Size: 2154 bytes --]

--- 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*/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Broken header dirent.h
  2014-07-12 17:54 Broken header dirent.h Ryan Johnson
@ 2014-07-14  8:49 ` Corinna Vinschen
  2014-07-14 14:51   ` Ryan Johnson
  0 siblings, 1 reply; 3+ messages in thread
From: Corinna Vinschen @ 2014-07-14  8:49 UTC (permalink / raw)
  To: cygwin-developers, Ryan Johnson

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

Hi Ryan,

On Jul 12 13:53, Ryan Johnson wrote:
> Hi all,
> 
> Please CC me in replies, I'm no longer a list member.

Given the massive amount of mail on this list I can see your point... ;)

> 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).

It doesn't have to be.  Including <sys/dirent.h> is not meant to be done
in application code.  The POSIX header is <dirent.h>, not <sys/dirent.h>:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html

If you include <dirent.h>, your linker problems should go away.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Broken header dirent.h
  2014-07-14  8:49 ` Corinna Vinschen
@ 2014-07-14 14:51   ` Ryan Johnson
  0 siblings, 0 replies; 3+ messages in thread
From: Ryan Johnson @ 2014-07-14 14:51 UTC (permalink / raw)
  To: cygwin-developers

On 14/07/2014 4:49 AM, Corinna Vinschen wrote:
> Hi Ryan,
>
> On Jul 12 13:53, Ryan Johnson wrote:
>> Hi all,
>>
>> Please CC me in replies, I'm no longer a list member.
> Given the massive amount of mail on this list I can see your point... ;)
Actually, I do seem to be a list member of this list after all. It's the 
main cygwin list that had too much traffic.

>> 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).
> It doesn't have to be.  Including <sys/dirent.h> is not meant to be done
> in application code.  The POSIX header is <dirent.h>, not <sys/dirent.h>:
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/dirent.h.html
>
> If you include <dirent.h>, your linker problems should go away.
Oops... I must have misread a man page somewhere. Could have sworn it 
said to use sys/dirent.h, but die.net (my usual go-to for man pages 
since I can't figure out how to install them locally) definitely agrees 
with you.

Thanks,
Ryan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-14 14:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-12 17:54 Broken header dirent.h Ryan Johnson
2014-07-14  8:49 ` Corinna Vinschen
2014-07-14 14:51   ` Ryan Johnson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).