Provide getcwd(NULL, 0) for Solaris (SunOS5)
authorHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Wed, 23 Mar 2016 21:53:27 +0000 (22:53 +0100)
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>
Thu, 24 Mar 2016 18:37:19 +0000 (19:37 +0100)
.editorconfig
src/OS/os.h-SunOS5
src/src/exim.c
src/src/os.c
src/src/osfunctions.h

index b348a15d8a9b658536e357ac2b437172eae26562..a781a03ae7e655a0427c7f0e989dfa35a04a82fc 100644 (file)
@@ -17,7 +17,7 @@ root = true
 end_of_line = lf
 insert_final_newline = true
 
-[*.{c,h}]
+[*.{c,h}{,-*}]
 indent_style = space
 indent_size = 2
 tab_width = 8
index 45a1171c8c1f632975daff4ebb3a7a99eb1017f2..807212b8564f22edaa5a86e08403d3dc18480f67 100644 (file)
@@ -37,4 +37,10 @@ it seems. */
 #endif
 
 
+/* SunOS5 doesn't accept getcwd(NULL, 0) to auto-allocate
+a buffer */
+
+#define OS_GETCWD
+
+
 /* End */
index 9cafc9a73110ac549c39a0aeee617a2650bfca62..6a4fb5af344087fe93942d96afbe79962a903863 100644 (file)
@@ -3748,7 +3748,7 @@ directory to "/"! Later we change to $spool_directory. We do it there, because
 during readconf_main() some expansion takes place already. */
 
 /* Store the initial cwd before we change directories */
-if ((initial_cwd = getcwd(NULL, 0)) == NULL)
+if ((initial_cwd = os_getcwd(NULL, 0)) == NULL)
   {
   perror("exim: can't get the current working directory");
   exit(EXIT_FAILURE);
index d9ca589ee308f31c03e70073eb940f1b3fea8a56..d40fb606d0e06c547649466db83d3e3a84977b70 100644 (file)
@@ -850,6 +850,38 @@ os_unsetenv(const char *name)
 }
 #endif
 
+/* ----------------------------------------------------------------------- */
+
+/***********************************************************
+*               getcwd()                                   *
+***********************************************************/
+
+/* Glibc allows getcwd(NULL, 0) to do auto-allocation. Some systems
+do auto-allocation, but need the size of the buffer, and others
+may not even do this. If the OS supports getcwd(NULL, 0) we'll use
+this, for all other systems we provide our own getcwd() */
+
+#if !defined(OS_GETCWD)
+char *
+os_getcwd(char *buffer, size_t size)
+{
+return getcwd(buffer, size);
+}
+#else
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+char *
+os_getcwd(char *buffer, size_t size)
+{
+void *rc;
+
+if (!size) size = PATH_MAX;
+if (!buffer && !(buffer = (char*) malloc(size))) return NULL;
+if (!(buffer = getcwd(buffer, size))) return NULL;
+return realloc(buffer, strlen(buffer) + 1);
+}
+#endif
 
 /* ----------------------------------------------------------------------- */
 
index 3d1914acb74a994f56ae6b5be9b11b139970add9..0e429fc8c712d29494f1b87bc6c28371c90d2978 100644 (file)
@@ -35,5 +35,8 @@ extern const char   *os_strsignal(int);   /* char to match strsignal in some OS
 #ifndef os_unsetenv
 extern int           os_unsetenv(const char *);
 #endif
+#ifndef os_getcwd
+extern char*         os_getcwd(char *, size_t);
+#endif
 
 /* End of osfunctions.h */