Branch: Tag:

2018-04-30

2018-04-30 10:49:14 by Henrik Grubbström (Grubba) <grubba@grubba.org>

I/O [Solaris]: Fix getcwd() on Solaris.

On Solaris getcwd(NULL, x) only works if x is > 0.

Fixes building issues on Solaris.

4282:   AC_MSG_CHECKING(for working getcwd)   AC_CACHE_VAL(pike_cv_func_working_getcwd,   [ + # First try getcwd(NULL, 0). + # This is the working == yes case, and is true on glibc and win32.   AC_TRY_RUN([   #ifndef _LARGEFILE_SOURCE   # define _FILE_OFFSET_BITS 64
4345:    signal(SIGALRM,sig_alarm);    alarm(4);   #endif /* !__NT__ */ +  tmp=getcwd(0,0); +  if(tmp && tmp[0] && (strlen(tmp) < 10000)) { +  free(tmp); +  exit(0); +  } +  exit(1); + } + ],pike_cv_func_working_getcwd=yes, + # The getcwd(NULL, 0) case failed. + # Retry with getcwd(NULL, 10000). + # This is the working == some case, and is true on Solaris. + AC_TRY_RUN([ + #ifndef _LARGEFILE_SOURCE + # define _FILE_OFFSET_BITS 64 + # define _LARGEFILE_SOURCE + # define _LARGEFILE64_SOURCE 1 + #endif + /* HPUX needs these too... */ + #ifndef __STDC_EXT__ + # define __STDC_EXT__ + #endif /* !__STDC_EXT__ */ +  + #ifndef POSIX_SOURCE + #define POSIX_SOURCE + #endif + #ifdef HAVE_UNISTD_H + #include <unistd.h> + #endif + #ifdef HAVE_DIRECT_H + #include <direct.h> + #endif /* HAVE_DIRECT_H */ + #ifdef HAVE_SYS_WAIT_H + #include <sys/wait.h> + #endif + #include <signal.h> +  + #include <stdlib.h> + #include <string.h> +  + #ifndef __NT__ + int sig_child(int arg) + { + #ifdef HAVE_WAITPID +  waitpid(-1,0,WNOHANG); + #else + #ifdef HAVE_WAIT3 +  wait3(0,WNOHANG,0); + #else + #ifdef HAVE_WAIT4 +  wait3(-1,0,WNOHANG,0); + #else +  +  /* Leave them hanging */ +  + #endif /* HAVE_WAIT4 */ + #endif /* HAVE_WAIT3 */ + #endif /* HAVE_WAITPID */ +  + #ifdef SIGNAL_ONESHOT +  signal(SIGCHLD, sig_child); + #endif + } +  + int sig_alarm() { exit(1); } + #endif /* !__NT__ */ +  + int main() + { +  char *tmp; + #ifndef __NT__ +  signal(SIGCHLD,sig_child); +  signal(SIGALRM,sig_alarm); +  alarm(4); + #endif /* !__NT__ */    tmp=getcwd(0,10000);    if(tmp && tmp[0] && (strlen(tmp) < 10000)) {    free(tmp);
4352:    }    exit(1);   } - ],pike_cv_func_working_getcwd=yes,pike_cv_func_working_getcwd=no, -  pike_cv_func_working_getcwd=yes)]) + ],pike_cv_func_working_getcwd=some, +  pike_cv_func_working_getcwd=no, +  # NB: This should be unreachable. +  pike_cv_func_working_getcwd=no), +  # Assume that getcwd(NULL, val) works. +  pike_cv_func_working_getcwd=some) + ])      if test "$pike_cv_func_working_getcwd" = yes; then    AC_MSG_RESULT(yes) -  AC_DEFINE(HAVE_WORKING_GETCWD) +  AC_DEFINE(HAVE_WORKING_GETCWD, [1]) + elif test "$pike_cv_func_working_getcwd" = some; then +  AC_MSG_RESULT(some) +  AC_DEFINE(HAVE_WORKING_GETCWD, [0])   else    AC_MSG_RESULT(no)   fi