#include "apue.h" #include <errno.h> #include <limits.h> #ifdef path_max static int pathmax = PA
Th_max;
#else static int pathmax = 0;
#endif #define SUSV3 200112L static long posix_version = 0; /* If Path_max is indeterminate, no guarantee it is adequate */#define PATH_MAX_GUESS 1024 char * path_alloc (int *s
IZEP)/* Also return allocated size, if nonnull/{char *ptr;
int size;
if (posix_version = = 0) posix_version = sysconf (_sc_version); if (Pathmax = = 0) {/*//* through/errno = 0;
/* from:http://www.bianceng.cn */if (Pathmax = pathconf ("/", _pc_path_max)) < 0) {if (errno = 0) Pathmax = path_max_guess;
/* it ' s indeterminate/Else Err_sys ("pathconf error for _pc_path_max"); else {pathmax++;
/* Add one since it ' s relative to root *} if (Posix_version < SUSV3) size = Pathmax + 1; else size = Pathmax;
if (ptr = malloc (size) = = NULL) Err_sys ("malloc error for pathname");
if (Sizep!= NULL) *sizep = size;
return (PTR); } or Char*path_alloc (int* size) {char *p = null; if (!size) return null; p = malloc (256); if (p) *size = 256; else *si
ze = 0;
return p; }