On 09/27/2012 06:15 AM, Liviu Nicoara wrote:
On 09/23/12 12:15, Liviu Nicoara wrote:
On 09/22/12 00:51, Liviu Nicoara wrote:
Optimized (but not debug) builds fail to compile setlocale.cpp with
the error:

A patch and a comment have been attached to the issue.

I am posting it here to save a trip to the JIRA issue. Any feed-back is
appreciated.

"The issue can be tracked down to the interaction between the definition
of _XOPEN_SOURCE in src/setlocale.cpp and util/path.cpp, the system
headers, and Solaris Studio C . It seems that the original purpose for
the definitions has been lost because both S_IFDIR and symlink are
defined and declared, respectively, on modern Linux (edit: by default).
Moreover, it seems that the original definition of _XOPEN_SOURCE was
incorrect, without a value. I propose we remove the two blocks – see the
patch."

I successfully tested the patch with GCC 3.4.6 on RHEL 4.8,
with GLIBC 2.3.4, the oldest Linux distribution I could get
my hands on.

That said, by my reading of POSIX, to get the definition of
S_IFDIR (marked as an XSI extension), a conforming application
is supposed to define the _XOPEN_SOURCE macro (to 500 or 600
depending on the version of POSIX) in order to get the former
macro defined. POSIX also says that every conforming application
should define _POSIX_C_SOURCE before including any header. We
don't try to do that (on Linux, GCC defines _GNU_SOURCE which
I think takes care of it, but I'm not sure we can count on it
with all other compilers on all other UNIX systems).

In any case, I think the patch is fine.

Martin


Thanks,
Liviu

Index: src/setlocale.cpp
===================================================================
--- src/setlocale.cpp    (revision 1388733)
+++ src/setlocale.cpp    (working copy)
@@ -33,11 +33,6 @@

  #include <rw/_defs.h>

-#if defined (__linux__) && !defined (_XOPEN_SOURCE)
-   // need S_IFDIR on Linux
-#  define _XOPEN_SOURCE
-#endif   // __linux__ && !_XOPEN_SOURCE
-
  #include <locale.h>   // for setlocale()
  #include <stdlib.h>   // for getenv()
  #include <string.h>   // for memcpy(), strcmp()
Index: util/path.cpp
===================================================================
--- util/path.cpp    (revision 1388733)
+++ util/path.cpp    (working copy)
@@ -27,16 +27,6 @@

**************************************************************************/

  #ifndef _WIN32
-#  ifdef __linux__
-     // for symlink()
-#    ifndef _XOPEN_SOURCE
-#      define _XOPEN_SOURCE
-#    endif
-#    ifndef _XOPEN_SOURCE_EXTENDED
-#      define _XOPEN_SOURCE_EXTENDED
-#    endif
-#  endif   // __linux__
-
  #  include <unistd.h>      // for getcwd()
  #  include <sys/stat.h>    // for struct stat, stat()
  #else


Reply via email to