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);
}
#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
/* ----------------------------------------------------------------------- */
#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 */