introduction of os-specific.c and os-specific.h
authorYang Tse <yangsita@gmail.com>
Fri, 5 Jun 2009 16:14:50 +0000 (16:14 +0000)
committerYang Tse <yangsita@gmail.com>
Fri, 5 Jun 2009 16:14:50 +0000 (16:14 +0000)
src/Makefile.Watcom
src/Makefile.inc
src/Makefile.riscos
src/Makefile.vc6
src/main.c
src/makefile.amiga
src/os-specific.c [new file with mode: 0644]
src/os-specific.h [new file with mode: 0644]
src/urlglob.c
src/vc6curlsrc.dsp

index c5b80bf..a8c66af 100644 (file)
@@ -14,7 +14,8 @@ OBJ_DIR = WC_Win32.obj
 
 OBJS = $(OBJ_DIR)\getpass.obj  $(OBJ_DIR)\homedir.obj  $(OBJ_DIR)\hugehelp.obj &
        $(OBJ_DIR)\main.obj     $(OBJ_DIR)\urlglob.obj  $(OBJ_DIR)\writeenv.obj &
-       $(OBJ_DIR)\writeout.obj $(OBJ_DIR)\curlutil.obj $(OBJ_DIR)\rawstr.obj
+       $(OBJ_DIR)\writeout.obj $(OBJ_DIR)\curlutil.obj $(OBJ_DIR)\rawstr.obj   &
+       $(OBJ_DIR)\os-specific.obj
 
 RESOURCE = $(OBJ_DIR)\curl.res
 
@@ -78,7 +79,8 @@ $(OBJ_DIR)\main.obj: main.c setup.h config-win32.h ..\lib\setup_once.h &
   version.h ..\include\curl\curlver.h ..\lib\curlx.h &
   ..\include\curl\mprintf.h ..\lib\strequal.h ..\lib\strtoofft.h &
   ..\lib\setup.h ..\lib\config-win32.h ..\include\curl\curlbuild.h &
-  ..\include\curl\curlrules.h ..\lib\timeval.h ..\lib\memdebug.h
+  ..\include\curl\curlrules.h ..\lib\timeval.h ..\lib\memdebug.h &
+  os-specific.h
 
 $(OBJ_DIR)\urlglob.obj: urlglob.c setup.h config-win32.h ..\lib\setup_once.h &
   ..\include\curl\curl.h ..\include\curl\curlver.h &
@@ -86,7 +88,7 @@ $(OBJ_DIR)\urlglob.obj: urlglob.c setup.h config-win32.h ..\lib\setup_once.h &
   ..\include\curl\easy.h ..\include\curl\multi.h ..\include\curl\curl.h &
   ..\include\curl\mprintf.h urlglob.h ..\lib\memdebug.h ..\lib\setup.h &
   ..\lib\config-win32.h ..\include\curl\curlbuild.h &
-  ..\include\curl\curlrules.h
+  ..\include\curl\curlrules.h os-specific.h
 
 $(OBJ_DIR)\writeenv.obj: writeenv.c setup.h config-win32.h ..\lib\setup_once.h
 
@@ -99,6 +101,9 @@ $(OBJ_DIR)\writeout.obj: writeout.c setup.h config-win32.h ..\lib\setup_once.h &
 $(OBJ_DIR)\curlutil.obj: curlutil.c setup.h config-win32.h ..\lib\setup_once.h &
   curlutil.h
 
+$(OBJ_DIR)\os-specific.obj: os-specific.c os-specific.h setup.h config-win32.h &
+  ..\lib\setup_once.h
+
 $(OBJ_DIR)\rawstr.obj: ..\lib\rawstr.c ..\lib\setup.h ..\lib\config-win32.h &
   ..\include\curl\curlbuild.h ..\include\curl\curlrules.h ..\lib\setup_once.h &
   ..\include\curl\curl.h ..\include\curl\curlver.h ..\include\curl\curlrules.h &
index 8c0a1f1..e0c1321 100644 (file)
@@ -7,10 +7,10 @@ CURLX_ONES =  $(top_srcdir)/lib/strtoofft.c \
        $(top_srcdir)/lib/rawstr.c 
 
 CURL_SOURCES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
-       getpass.c homedir.c curlutil.c
+       getpass.c homedir.c curlutil.c os-specific.c
 
 CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
-       config-riscos.h urlglob.h version.h \
+       config-riscos.h urlglob.h version.h os-specific.h \
        writeout.h writeenv.h getpass.h homedir.h curlutil.h
 
 curl_SOURCES = $(CURL_SOURCES) $(CURLX_ONES) $(CURL_HFILES)
index 5dc775c..ad7dc6d 100644 (file)
@@ -22,6 +22,9 @@ o.hugehelp:   c.hugehelp
 o.main:        c.main
                gcc $(compileropts) -c -o main.o c.main
 
+o.os-specific: c.os-specific
+               gcc $(compileropts) -c -o os-specific.o c.os-specific
+
 o.urlglob:     c.urlglob
                gcc $(compileropts) -c -o urlglob.o c.urlglob
 
@@ -39,12 +42,18 @@ o.hugehelp: c.hugehelp
 
 o.main:        c.main
 o.main:        h.setup
+o.main:        h.os-specific
 o.main:        h.urlglob
 o.main:        h.writeout
 o.main:        h.version
 
+o.os-specific: c.os-specific
+o.os-specific: h.setup
+o.os-specific: h.os-specific
+
 o.urlglob:     c.urlglob
 o.urlglob:     h.setup
+o.urlglob:     h.os-specific
 o.urlglob:     h.urlglob
 
 o.writeout:    c.writeout
index e85ca2f..e6236aa 100644 (file)
@@ -98,6 +98,7 @@ RELEASE_OBJS= \
        getpassr.obj \\r
        homedirr.obj \\r
        curlutilr.obj \\r
+       os-specificr.obj \\r
        rawstrr.obj \\r
        strtoofftr.obj \\r
        mainr.obj \\r
@@ -110,6 +111,7 @@ DEBUG_OBJS= \
        getpassd.obj \\r
        homedird.obj \\r
        curlutild.obj \\r
+       os-specificd.obj \\r
        rawstrd.obj \\r
        strtoofftd.obj \\r
        maind.obj \\r
@@ -247,6 +249,8 @@ homedirr.obj: homedir.c
        $(CCR) $(CFLAGS) /Fo"$@" homedir.c\r
 curlutilr.obj: curlutil.c\r
        $(CCR) $(CFLAGS) /Fo"$@" curlutil.c\r
+os-specificr.obj: os-specific.c\r
+       $(CCR) $(CFLAGS) /Fo"$@" os-specific.c\r
 rawstrr.obj: ../lib/rawstr.c\r
        $(CCR) $(CFLAGS) /Fo"$@" ../lib/rawstr.c\r
 strtoofftr.obj: ../lib/strtoofft.c\r
@@ -269,6 +273,8 @@ homedird.obj: homedir.c
        $(CCD) $(CFLAGS) /Fo"$@" homedir.c\r
 curlutild.obj: curlutil.c\r
        $(CCD) $(CFLAGS) /Fo"$@" curlutil.c\r
+os-specificd.obj: os-specific.c\r
+       $(CCD) $(CFLAGS) /Fo"$@" os-specific.c\r
 rawstrd.obj: ../lib/rawstr.c\r
        $(CCD) $(CFLAGS) /Fo"$@" ../lib/rawstr.c\r
 strtoofftd.obj: ../lib/strtoofft.c\r
index 77de03b..586d00e 100644 (file)
 #include <netinet/tcp.h> /* for TCP_KEEPIDLE, TCP_KEEPINTVL */
 #endif
 
+#ifdef __VMS
+#  include "curlmsg_vms.h"
+#endif
+
+#include "os-specific.h"
+
 /* The last #include file should be: */
 #ifdef CURLDEBUG
 #ifndef CURLTOOLDEBUG
@@ -200,10 +206,6 @@ typedef enum {
 #define mkdir(x,y) (mkdir)(x)
 #endif
 
-#ifdef  VMS
-#include "curlmsg_vms.h"
-#endif
-
 /*
  * Large file support (>2Gb) using WIN32 functions.
  */
@@ -4996,16 +4998,21 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
 
 show_error:
 
-#ifdef  VMS
-        if (!config->showerror)  {
-          vms_show = VMSSTS_HIDE;
+#ifdef __VMS
+        if(is_vms_shell()) {
+          /* VMS DCL shell behavior */
+          if(!config->showerror) {
+            vms_show = VMSSTS_HIDE;
+          }
         }
-#else
-        if((res!=CURLE_OK) && config->showerror) {
-          fprintf(config->errors, "curl: (%d) %s\n", res,
-                  errorbuffer[0]? errorbuffer:
-                  curl_easy_strerror((CURLcode)res));
-          if(CURLE_SSL_CACERT == res) {
+        else
+#endif
+        {
+          if((res!=CURLE_OK) && config->showerror) {
+            fprintf(config->errors, "curl: (%d) %s\n", res,
+                    errorbuffer[0]? errorbuffer:
+                    curl_easy_strerror((CURLcode)res));
+            if(CURLE_SSL_CACERT == res) {
 #define CURL_CA_CERT_ERRORMSG1 \
 "More details here: http://curl.haxx.se/docs/sslcerts.html\n\n" \
 "curl performs SSL certificate verification by default, using a \"bundle\"\n" \
@@ -5021,12 +5028,12 @@ show_error:
 "If you'd like to turn off curl's verification of the certificate, use\n" \
 " the -k (or --insecure) option.\n"
 
-            fprintf(config->errors, "%s%s",
-                    CURL_CA_CERT_ERRORMSG1,
-                    CURL_CA_CERT_ERRORMSG2 );
+              fprintf(config->errors, "%s%s",
+                      CURL_CA_CERT_ERRORMSG1,
+                      CURL_CA_CERT_ERRORMSG2 );
+            }
           }
         }
-#endif
 
         if (outfile && !curlx_strequal(outfile, "-") && outs.stream)
           fclose(outs.stream);
@@ -5182,9 +5189,8 @@ int main(int argc, char *argv[])
 #ifdef __NOVELL_LIBC__
   pressanykey();
 #endif
-#ifdef  VMS
-  if (res > CURL_LAST) res = CURL_LAST; /* If CURL_LAST exceeded then */
-  return (vms_cond[res]|vms_show);      /* curlmsg.h is out of sync.  */
+#ifdef __VMS
+  vms_special_exit(res, vms_show);
 #else
   return res;
 #endif
index 2608744..c2371a6 100644 (file)
@@ -14,7 +14,7 @@ MANPAGE =     ../docs/curl.1
 README =       ../docs/MANUAL
 MKHELP =       ../src/mkhelp.pl
 
-OBJS   =       getpass.c hugehelp.c main.c urlglob.c writeenv.c writeout.c curlutil.c ../lib/rawstr.c
+OBJS   =       getpass.c hugehelp.c main.c urlglob.c writeenv.c writeout.c curlutil.c os-specific.c ../lib/rawstr.c
 
 
 all:   hugehelp.c $(OBJS:.c=.o)
diff --git a/src/os-specific.c b/src/os-specific.c
new file mode 100644 (file)
index 0000000..457368d
--- /dev/null
@@ -0,0 +1,112 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+#include "setup.h"
+
+#include <curl/curl.h>
+
+#ifdef __VMS
+#  include "curlmsg_vms.h"
+#endif
+
+#define ENABLE_CURLX_PRINTF
+#include "curlx.h"
+
+#include "os-specific.h"
+
+#if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
+#  include "memdebug.h"
+#endif
+
+#ifdef __VMS
+
+int vms_shell = -1;
+
+/* VMS has a DCL shell and and also has Unix shells ported to it.
+ * When curl is running under a Unix shell, we want it to be as much
+ * like Unix as possible.
+ */
+int is_vms_shell(void)
+{
+  char *shell;
+
+  /* Have we checked the shell yet? */
+  if(vms_shell >= 0)
+    return vms_shell;
+
+  shell = getenv("SHELL");
+
+  /* No shell, means DCL */
+  if(shell == NULL) {
+    vms_shell = 1;
+    return 1;
+  }
+
+  /* Have to make sure some one did not set shell to DCL */
+  if(strcmp(shell, "DCL") == 0) {
+    vms_shell = 1;
+    return 1;
+  }
+
+  vms_shell = 0;
+  return 0;
+}
+
+/*
+ * VMS has two exit() routines.  When running under a Unix style shell, then
+ * Unix style and the __posix_exit() routine is used.
+ *
+ * When running under the DCL shell, then the VMS encoded codes and decc$exit()
+ * is used.
+ *
+ * We can not use exit() or return a code from main() because the actual
+ * routine called depends on both the compiler version, compile options, and
+ * feature macro settings, and one of the exit routines is hidden at compile
+ * time.
+ *
+ * Since we want Curl to work properly under the VMS DCL shell and Unix
+ * shells under VMS, this routine should compile correctly regardless of
+ * the settings.
+ */
+
+void vms_special_exit(int code, int vms_show)
+{
+  int vms_code;
+
+  /* The Posix exit mode is only available after VMS 7.0 */
+#if __CRTL_VER >= 70000000
+  if(is_vms_shell() == 0) {
+    decc$__posix_exit(code);
+  }
+#endif
+
+  if(code > CURL_LAST) {   /* If CURL_LAST exceeded then */
+    vms_code = CURL_LAST;  /* curlmsg.h is out of sync.  */
+  }
+  else {
+    vms_code = vms_cond[code] | vms_show;
+  }
+  decc$exit(vms_code);
+}
+
+#endif /* __VMS */
+
diff --git a/src/os-specific.h b/src/os-specific.h
new file mode 100644 (file)
index 0000000..96f91cb
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef HEADER_CURL_OS_SPECIFIC_H
+#define HEADER_CURL_OS_SPECIFIC_H
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#ifdef __VMS
+
+extern int vms_shell;
+
+void decc$__posix_exit(int __status);
+void decc$exit(int __status);
+
+int is_vms_shell(void);
+void vms_special_exit(int code, int vms_show);
+
+#undef exit
+#define exit(__code) vms_special_exit((__code), (0))
+
+#endif /* __VMS */
+
+#endif /* HEADER_CURL_OS_SPECIFIC_H */
index 5f9a3e5..afbb66c 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -34,6 +34,7 @@
 #include <curl/mprintf.h>
 
 #include "urlglob.h"
+#include "os-specific.h"
 
 #if defined(CURLDEBUG) && defined(CURLTOOLDEBUG)
 #include "memdebug.h"
index cba6924..e888451 100644 (file)
@@ -159,6 +159,10 @@ SOURCE=.\main.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\os-specific.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=..\lib\rawstr.c\r
 # End Source File\r
 # Begin Source File\r
@@ -203,6 +207,10 @@ SOURCE=.\hugehelp.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\os-specific.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\setup.h\r
 # End Source File\r
 # Begin Source File\r