Index: config_office/configure.in
===================================================================
RCS file: /cvs/tools/config_office/configure.in,v
retrieving revision 1.169
diff -u -u -r1.169 configure.in
--- config_office/configure.in	10 Jul 2006 19:00:12 -0000	1.169
+++ config_office/configure.in	19 Jul 2006 10:35:14 -0000
@@ -3727,6 +3727,10 @@
       AC_MSG_ERROR([no, upgrade libc])
    fi
 fi
+AC_CHECK_FUNC(getopt, HAVE_GETOPT=YES, HAVE_GETOPT=NO)
+AC_CHECK_FUNC(readdir_r, HAVE_READDIR_R=YES, HAVE_READDIR_R=NO)
+AC_SUBST(HAVE_READDIR_R)
+AC_SUBST(HAVE_GETOPT)
 
 dnl =========================================
 dnl Check for the Microsoft Platform SDK.
Index: config_office/set_soenv.in
===================================================================
RCS file: /cvs/tools/config_office/set_soenv.in,v
retrieving revision 1.107
diff -u -u -r1.107 set_soenv.in
--- config_office/set_soenv.in	5 Jul 2006 22:32:39 -0000	1.107
+++ config_office/set_soenv.in	19 Jul 2006 10:35:14 -0000
@@ -1577,6 +1577,8 @@
 ToFile( "CVER",              $CVER,              "e" );
 ToFile( "GUI",               $GUI,               "e" );
 ToFile( "GLIBC",             $GLIBC,             "e" );
+ToFile( "HAVE_GETOPT",       "@HAVE_GETOPT@",    "e" );
+ToFile( "HAVE_READDIR_R",    "@HAVE_READDIR_R@", "e" );
 ToFile( "GUIBASE",           $GUIBASE,           "e" );
 ToFile( "GUIENV",            $GUIENV,            "e" );
 ToFile( "GVER",              $GVER,              "e" );
Index: extensions/source/plugin/unx/makefile.mk
===================================================================
RCS file: /cvs/util/extensions/source/plugin/unx/makefile.mk,v
retrieving revision 1.12
diff -u -u -r1.12 makefile.mk
--- extensions/source/plugin/unx/makefile.mk	19 Jun 2006 10:45:51 -0000	1.12
+++ extensions/source/plugin/unx/makefile.mk	19 Jul 2006 10:36:22 -0000
@@ -80,6 +80,14 @@
 .ENDIF
 .ENDIF
 
+.IF "$(HAVE_READDIR_R)" != "YES"
+.IF "$(OS)" == "WNT"
+APP1STDLIBS+= gnu_readdir.lib
+.ELSE
+APP1STDLIBS+=-lgnu_readdir_r
+.ENDIF
+.ENDIF
+
 APP1DEF=	$(MISC)$/$(TARGET).def
 
 .ENDIF # $(WITH_MOZILLA) != "NO"
Index: idlc/source/preproc/makefile.mk
===================================================================
RCS file: /cvs/udk/idlc/source/preproc/makefile.mk,v
retrieving revision 1.4
diff -u -u -r1.4 makefile.mk
--- idlc/source/preproc/makefile.mk	7 Sep 2005 18:15:31 -0000	1.4
+++ idlc/source/preproc/makefile.mk	19 Jul 2006 10:36:49 -0000
@@ -52,7 +52,6 @@
 CXXFILES=   \
 			cpp.c	\
 			eval.c	\
-			getopt.c	\
 			include.c	\
 			lex.c	\
 			macro.c	\
@@ -63,13 +62,22 @@
 OBJFILES=   \
 			$(OBJ)$/cpp.obj	\
 			$(OBJ)$/eval.obj	\
-			$(OBJ)$/getopt.obj	\
 			$(OBJ)$/include.obj	\
 			$(OBJ)$/lex.obj	\
 			$(OBJ)$/macro.obj	\
 			$(OBJ)$/nlist.obj	\
 			$(OBJ)$/tokens.obj	\
 			$(OBJ)$/unix.obj
+
+.IF "$(HAVE_GETOPT)"!="YES"
+.IF "$(OS)" == "WNT"
+APP1STDLIBS+= gnu_getopt.lib
+.ELSE
+APP1STDLIBS+= -lgnu_getopt
+.ENDIF
+.ELSE
+CDEFS+= -DHAVE_GETOPT
+.ENDIF
 
 # --- CPP -------------------------------------------------------
 
Index: idlc/source/preproc/nlist.c
===================================================================
RCS file: /cvs/udk/idlc/source/preproc/nlist.c,v
retrieving revision 1.3
diff -u -u -r1.3 nlist.c
--- idlc/source/preproc/nlist.c	20 Jun 2006 03:51:46 -0000	1.3
+++ idlc/source/preproc/nlist.c	19 Jul 2006 10:36:49 -0000
@@ -37,9 +37,13 @@
 #include <string.h>
 #include "cpp.h"
 
+#ifndef HAVE_GETOPT
 extern int getopt(int, char *const *, const char *);
 extern char *optarg;
 extern int optind;
+#else
+#include <getopt.h>
+#endif
 extern int Cplusplus;
 Nlist *kwdefined;
 char wd[128];
Index: idlc/source/preproc/unix.c
===================================================================
RCS file: /cvs/udk/idlc/source/preproc/unix.c,v
retrieving revision 1.6
diff -u -u -r1.6 unix.c
--- idlc/source/preproc/unix.c	20 Jun 2006 03:52:12 -0000	1.6
+++ idlc/source/preproc/unix.c	19 Jul 2006 10:36:49 -0000
@@ -46,10 +46,14 @@
 
 #include "cpp.h"
 
+#ifndef HAVE_GETOPT
 extern int getopt(int, char *const *, const char *);
-extern char *optarg, rcsid[];
+extern char *optarg;
 extern int optind;
-
+#else
+#include <getopt.h>
+#endif
+extern char rcsid[];
 int Pflag = 0;                          /* print no line information */
 int Iflag = 0;							/* print includes */
 int Mflag = 0;                          /* print macor expansion */
Index: sal/osl/unx/makefile.mk
===================================================================
RCS file: /cvs/porting/sal/osl/unx/makefile.mk,v
retrieving revision 1.27
diff -u -u -r1.27 makefile.mk
--- sal/osl/unx/makefile.mk	8 Sep 2005 14:57:34 -0000	1.27
+++ sal/osl/unx/makefile.mk	19 Jul 2006 10:38:49 -0000
@@ -54,6 +54,16 @@
 
 .INCLUDE :  settings.mk
 
+.IF "$(HAVE_READDIR_R)"=="YES"
+CDEFS+=-DHAVE_READDIR_H
+.ELSE
+.IF "$(OS)" == "WNT"
+SHL1STDLIBS+= gnu_readdir.lih
+.ELSE
+SHL1STDLIBS+= -lgnu_readdir
+.ENDIF
+.ENDIF
+
 # --- Files --------------------------------------------------------
 
 SLOFILES=   $(SLO)$/conditn.obj  \
Index: sal/osl/unx/system.c
===================================================================
RCS file: /cvs/porting/sal/osl/unx/system.c,v
retrieving revision 1.12
diff -u -u -r1.12 system.c
--- sal/osl/unx/system.c	20 Jun 2006 04:19:35 -0000	1.12
+++ sal/osl/unx/system.c	19 Jul 2006 10:38:49 -0000
@@ -440,6 +440,8 @@
  * in MacOS X 10.1.x and earlier.
  */
 
+#ifndef HAVE_READDIR_H
+
 /* MacOS X doesn't have readdir_r() standard, plus readdir() isn't threadsafe. */
 
 /*******************************************************************************/
@@ -477,6 +479,8 @@
 
     return nRet;
 }
+
+#endif
 
 /* No reentrant asctime() either... */
 
Index: sal/osl/unx/system.h
===================================================================
RCS file: /cvs/porting/sal/osl/unx/system.h,v
retrieving revision 1.32
diff -u -u -r1.32 system.h
--- sal/osl/unx/system.h	20 Jun 2006 04:19:46 -0000	1.32
+++ sal/osl/unx/system.h	19 Jul 2006 10:38:49 -0000
@@ -366,7 +366,9 @@
 #	define  NO_PTHREAD_RTL
 /* for NSGetArgc/Argv/Environ */
 #       include <crt_externs.h>
+#ifndef HAVE_READDIR_H
 int  readdir_r( DIR *dirp, struct dirent *entry, struct dirent **result );
+#endif
 char *asctime_r( const struct tm *tm, char *buffer );
 void macxp_getSystemVersion( unsigned int *isDarwin, unsigned int *majorVersion, unsigned int *minorVersion, unsigned int *minorMinorVersion );
 #ifdef __cplusplus
Index: soltools/javadep/javadep.c
===================================================================
RCS file: /cvs/tools/soltools/javadep/javadep.c,v
retrieving revision 1.8
diff -u -u -r1.8 javadep.c
--- soltools/javadep/javadep.c	20 Jun 2006 05:08:14 -0000	1.8
+++ soltools/javadep/javadep.c	19 Jul 2006 10:39:21 -0000
@@ -62,6 +62,8 @@
 #define ntohs(x)    ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)) 
 #endif
 
+#include <getopt.h>
+
 /* max. length of line in response file */
 #define RES_FILE_BUF    65536
 
@@ -144,13 +146,6 @@
 void    err_quit(const char *, ...);
 void    silent_quit(void);
 
-/* poor man's getopt() */
-int     simple_getopt(char *pargv[], const char *poptstring);
-char    *optarg = NULL;
-int     optind  = 1;
-int     optopt  = 0;
-int     opterr  = 0;
-
 uint8
 read_uint8(const file_t *pfile)
 {
@@ -774,45 +769,6 @@
             pprogname);
 }
 
-/* my very simple minded implementation of getopt()
- * it's to sad that getopt() is not available everywhere
- * note: this is not a full POSIX conforming getopt()
- */
-int simple_getopt(char *pargv[], const char *poptstring)
-{
-    char *parg = pargv[optind];
-
-    /* skip all response file arguments */
-    if ( parg ) {
-        while ( *parg == '@' )
-            parg = pargv[++optind];
-        
-        if ( parg[0] == '-' && parg[1] != '\0' ) {
-            char *popt;
-            int c = parg[1];
-            if ( (popt = strchr(poptstring, c)) == NULL ) {
-                optopt = c;
-                if ( opterr )
-                    fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
-                return '?';
-            }
-            if ( *(++popt) == ':') {
-                if ( parg[2] != '\0' ) {
-                    optarg = ++parg;
-                } else {
-                    optarg = pargv[++optind];
-                }
-            } else {
-                optarg = NULL;
-            }
-            ++optind;
-            return c;
-        }
-    }
-    return -1;
-}
-
-
 int CDECL
 main(int argc, char *argv[])
 {
@@ -860,7 +816,7 @@
     opterr = 0;
     pincs = allocate_growable();
 
-    while( (c = simple_getopt(pall_argv, ":i:I:s:S:o:OhHvV")) != -1 ) {
+    while( (c = getopt(nall_argc, pall_argv, ":i:I:s:S:o:OhHvV")) != -1 ) {
         switch(c) {
             case 'i':
             case 'I':
Index: soltools/javadep/makefile.mk
===================================================================
RCS file: /cvs/tools/soltools/javadep/makefile.mk,v
retrieving revision 1.7
diff -u -u -r1.7 makefile.mk
--- soltools/javadep/makefile.mk	8 Sep 2005 07:27:39 -0000	1.7
+++ soltools/javadep/makefile.mk	19 Jul 2006 10:39:21 -0000
@@ -49,6 +49,16 @@
 UWINAPILIB=$(0)
 LIBSALCPPRT=$(0)
 
+.IF "$(HAVE_GETOPT)"=="YES"
+CDEFS+=-DHAVE_GETOPT
+.ELSE
+.IF "$(OS)" == "WNT"
+APP1STDLIBS+= gnu_getopt.lib
+.ELSE
+APP1STDLIBS+=-lgnu_getopt
+.ENDIF
+.ENDIF
+
 # --- Files --------------------------------------------------------
 
 APP1TARGET	= 	javadep
Index: tools/bootstrp/makefile.mk
===================================================================
RCS file: /cvs/util/tools/bootstrp/makefile.mk,v
retrieving revision 1.22
diff -u -u -r1.22 makefile.mk
--- tools/bootstrp/makefile.mk	9 Sep 2005 13:30:26 -0000	1.22
+++ tools/bootstrp/makefile.mk	19 Jul 2006 10:40:13 -0000
@@ -97,6 +97,14 @@
 APP2LIBS=   $(LB)$/$(TARGET).lib $(LB)$/$(TARGET1).lib
 APP2STDLIBS= $(SALLIB) $(VOSLIB) $(TOOLSLIB)
 
+.IF "$(HAVE_GETOPT)"!="YES"
+.IF "$(OS)" == "WNT"
+APP2STDLIBS+= gnu_getopt.lib
+.ELSE
+APP2STDLIBS+= -lgnu_getopt
+.ENDIF
+.ENDIF
+
 APP3TARGET=  so_checksum
 APP3OBJS=    $(OBJ)$/md5.obj \
              $(OBJ)$/so_checksum.obj
Index: tools/bootstrp/rscdep.cxx
===================================================================
RCS file: /cvs/util/tools/bootstrp/rscdep.cxx,v
retrieving revision 1.21
diff -u -u -r1.21 rscdep.cxx
--- tools/bootstrp/rscdep.cxx	19 Jun 2006 13:21:59 -0000	1.21
+++ tools/bootstrp/rscdep.cxx	19 Jul 2006 10:40:13 -0000
@@ -49,6 +49,8 @@
 
 #include "cppdep.hxx"
 
+#include <getopt.h>
+
 class RscHrcDep : public CppDep
 {
 public:
@@ -74,16 +76,6 @@
 
 //static String aDelim;
 
-/* poor man's getopt() */
-int     simple_getopt(char *argv[], const char *optstring);
-#ifdef WNT
-static char	*optarg = NULL;
-static int	optind = 1; 
-static int	optopt = 0; 
-static int	opterr = 0; 
-#endif
-
-
 int
 #ifdef WNT
 _cdecl
@@ -175,7 +167,7 @@
 
 	while( 1 )
 	{
-		c = simple_getopt( argv,
+		c = getopt( argc, argv,
 		"_abcdefghi:jklmnopqrstuvwxyzABCDEFGHI:JKLMNOPQRSTUVWXYZ1234567890/-+=.\\()\"");
 		if ( c == -1 )
 			break;
@@ -293,43 +285,5 @@
 	aOutStream.Close();
 
 	return 0;
-}
-
-/* my very simple minded implementation of getopt()
- * it's too sad that getopt() is not available everywhere
- * note: this is not a full POSIX conforming getopt()
- */
-int simple_getopt(char *argv[], const char *optstring)
-{
-    char *arg = argv[optind];
-
-    /* skip all response file arguments */
-    if ( arg ) {
-		while ( *arg == '@' )
-        	arg = argv[++optind];
-        
-    	if ( arg[0] == '-' && arg[1] != '\0' ) {
-        	const char *popt;
-        	int c = arg[1];
-        	if ( (popt = strchr(optstring, c)) == NULL ) {
-            	optopt = c;
-            	if ( opterr )
-                	fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
-            	return '?';
-        	}
-        	if ( *(++popt) == ':') {
-             	if ( arg[2] != '\0' ) {
-                 	optarg = ++arg;
-             	} else {
-                 	optarg = argv[++optind];
-             	}
-         	} else {
-             	optarg = NULL;
-         	}
-         	++optind;
-         	return c;
-    	}
-	}
-    return -1;
 }
 
Index: glibc-2.1.3.patch
===================================================================
RCS file: /cvs/util/external/Attic/glibc-2.1.3.patch,v
retrieving revision 1.1.2.1
diff -u -u -r1.1.2.1 glibc-2.1.3.patch
--- external/glibc-2.1.3.patch	11 Aug 2006 10:48:49 -0000	1.1.2.1
+++ external/glibc-2.1.3.patch	18 Aug 2006 21:32:24 -0000
@@ -59,7 +59,7 @@
 ***************
 *** 1 ****
 ! dummy
---- 1,73 ----
+--- 1,77 ----
 ! #*************************************************************************
 ! #
 ! #   OpenOffice.org - a multi-platform office productivity suite
@@ -115,6 +115,8 @@
 ! 
 ! # --- Files --------------------------------------------------------
 ! 
+! .IF "$(HAVE_GETOPT)" != "YES"
+! 
 ! OBJFILES=	$(OBJ)$/getopt.obj		\
 ! 			$(OBJ)$/getopt1.obj
 ! 
@@ -122,7 +124,9 @@
 ! LIB1ARCHIV=$(LB)$/lib$(TARGET).a
 ! LIB1OBJFILES=$(OBJFILES)
 ! 
-! .IF "$(OS)"=="NETBSD"
+! .ENDIF
+! 
+! .IF "$(HAVE_READDIR_R)" != "YES"
 ! TARGET2=gnu_readdir_r
 ! OBJFILES+= $(OBJ)$/readdir_r.obj
 ! LIB2TARGET=$(SLB)$/$(TARGET2).lib
Index: glibc/makefile.mk
===================================================================
RCS file: /cvs/util/external/glibc/makefile.mk,v
retrieving revision 1.7.30.1
diff -u -u -r1.7.30.1 makefile.mk
--- external/glibc/makefile.mk	11 Aug 2006 10:47:02 -0000	1.7.30.1
+++ external/glibc/makefile.mk	18 Aug 2006 21:32:24 -0000
@@ -44,6 +44,7 @@
 
 # --- Files --------------------------------------------------------
 
+.IF "$(HAVE_GETOPT)" != "YES" || "$(HAVE_READDIR_R)" != "YES"
 TARFILE_NAME=glibc-2.1.3-stub
 TARFILE_ROOTDIR=glibc-2.1.3
 ADDITIONAL_FILES=posix$/makefile.mk posix$/config.h posix$/readdir_r.c
@@ -55,6 +56,10 @@
 
 BUILD_DIR=posix
 BUILD_ACTION=dmake $(MFLAGS) $(CALLMACROS)
+.ELSE
+@all:
+	@echo "Nothing to do here."
+.ENDIF
 
 # --- Targets ------------------------------------------------------
 
Index: prj/d.lst
===================================================================
RCS file: /cvs/util/external/prj/d.lst,v
retrieving revision 1.25.4.4
diff -u -u -r1.25.4.4 d.lst
--- external/prj/d.lst	17 Aug 2006 10:32:41 -0000	1.25.4.4
+++ external/prj/d.lst	18 Aug 2006 21:39:06 -0000
@@ -7,8 +7,8 @@
 ..\atl\rtufiles\*.idl %_DEST%\inc%_EXT%\external\atl\*.idl
 ..\atl\rtufiles\*.cpp %_DEST%\inc%_EXT%\external\atl\*.cpp
 ..\dt\rtufiles\*.h %_DEST%\inc%_EXT%\external\dt\*.h
-..\glibc\rtufiles\config.h %_DEST%\inc%_EXT%\external\glibc\config.h
-..\glibc\rtufiles\getopt.h %_DEST%\inc%_EXT%\external\glibc\getopt.h
+..\%__SRC%\misc/build/glibc-2.1.3/posix/config.h %_DEST%\inc%_EXT%\external\glibc\config.h
+..\%__SRC%\misc/build/glibc-2.1.3/posix/getopt.h %_DEST%\inc%_EXT%\external\glibc\getopt.h
 ..\gpc\gpc.h %_DEST%\inc%_EXT%\external\gpc\gpc.h
 
 ..\%__SRC%\slb\gnu_getopt.lib %_DEST%\lib%_EXT%\gnu_getopt.lib
Index: _nlist.c
===================================================================
RCS file: /cvs/tools/soltools/cpp/_nlist.c,v
retrieving revision 1.3
diff -u -u -r1.3 _nlist.c
--- soltools/cpp/_nlist.c	20 Jun 2006 05:06:54 -0000	1.3
+++ soltools/cpp/_nlist.c	3 Sep 2006 20:13:15 -0000
@@ -1,9 +1,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <getopt.h>
 #include "cpp.h"
 
-extern int getopt(int, char *const *, const char *);
 extern char *optarg;
 extern int optind;
 extern int Cplusplus;
Index: _unix.c
===================================================================
RCS file: /cvs/tools/soltools/cpp/_unix.c,v
retrieving revision 1.4
diff -u -u -r1.4 _unix.c
--- soltools/cpp/_unix.c	20 Jun 2006 05:07:17 -0000	1.4
+++ soltools/cpp/_unix.c	3 Sep 2006 20:13:15 -0000
@@ -9,10 +9,10 @@
 #else
 #include <unistd.h>
 #endif
+#include <getopt.h>
 
 #include "cpp.h"
 
-extern int getopt(int, char *const *, const char *);
 extern char *optarg, rcsid[];
 extern int optind;
 
Index: makefile.mk
===================================================================
RCS file: /cvs/tools/soltools/cpp/makefile.mk,v
retrieving revision 1.9
diff -u -u -r1.9 makefile.mk
--- soltools/cpp/makefile.mk	8 Sep 2005 07:23:35 -0000	1.9
+++ soltools/cpp/makefile.mk	3 Sep 2006 20:13:15 -0000
@@ -54,7 +54,6 @@
 OBJFILES= \
 	$(OBJ)$/_cpp.obj		\
 	$(OBJ)$/_eval.obj 	\
-	$(OBJ)$/_getopt.obj	\
 	$(OBJ)$/_include.obj \
 	$(OBJ)$/_lex.obj 	\
 	$(OBJ)$/_macro.obj 	\
@@ -62,6 +61,16 @@
 	$(OBJ)$/_nlist.obj 	\
 	$(OBJ)$/_tokens.obj 	\
 	$(OBJ)$/_unix.obj
+
+.IF "$(HAVE_GETOPT)"!="YES"
+.IF "$(OS)" == "WNT"
+APP1STDLIBS+= gnu_getopt.lib
+.ELSE
+APP1STDLIBS+= -lgnu_getopt
+.ENDIF
+.ELSE
+CDEFS+= -DHAVE_GETOPT
+.ENDIF
 
 APP1TARGET	=	$(TARGET)
 APP1STACK	=	1000000
