From: Heiko Schlittermann (HS12-RIPE) Date: Wed, 23 Mar 2016 21:53:27 +0000 (+0100) Subject: Provide getcwd(NULL, 0) for Solaris (SunOS5) X-Git-Tag: exim-4_87_RC7~3 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3ae121c94f0dfaeba5938de26931c49e29677d0a;p=exim.git Provide getcwd(NULL, 0) for Solaris (SunOS5) --- diff --git a/.editorconfig b/.editorconfig index b348a15d8..a781a03ae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 diff --git a/src/OS/os.h-SunOS5 b/src/OS/os.h-SunOS5 index 45a1171c8..807212b85 100644 --- a/src/OS/os.h-SunOS5 +++ b/src/OS/os.h-SunOS5 @@ -37,4 +37,10 @@ it seems. */ #endif +/* SunOS5 doesn't accept getcwd(NULL, 0) to auto-allocate +a buffer */ + +#define OS_GETCWD + + /* End */ diff --git a/src/src/exim.c b/src/src/exim.c index 9cafc9a73..6a4fb5af3 100644 --- a/src/src/exim.c +++ b/src/src/exim.c @@ -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); diff --git a/src/src/os.c b/src/src/os.c index d9ca589ee..d40fb606d 100644 --- a/src/src/os.c +++ b/src/src/os.c @@ -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 /* ----------------------------------------------------------------------- */ diff --git a/src/src/osfunctions.h b/src/src/osfunctions.h index 3d1914acb..0e429fc8c 100644 --- a/src/src/osfunctions.h +++ b/src/src/osfunctions.h @@ -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 */