1 /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
2 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
3 #include <errno.h>
4 #include <stdlib.h>
5 #include <ctype.h>
6 #include <unistd.h>
7 #include <fcntl.h>
8 #include <limits.h>
9 
10 #define TOLOWER(c) (isascii(c) && isupper(c) ? tolower (c) : (c))
11 
12 long
pathconf(const char * path,int name)13 pathconf(const char *path, int name)
14 {
15   switch (name)
16   {
17   case _PC_LINK_MAX:		return LINK_MAX;
18   case _PC_MAX_CANON:		return MAX_CANON;
19   case _PC_MAX_INPUT:		return MAX_INPUT;
20   case _PC_NAME_MAX: case _PC_PATH_MAX:
21     {
22       int name_max, path_max;
23       int e = errno;
24       char *lfnenv = getenv ("LFN");
25 
26       if (!lfnenv || TOLOWER (*lfnenv) != 'n')
27 	{
28 	  errno = 0;
29 	  _get_volume_info (path, &name_max, &path_max, 0);
30 	  if (!errno)
31 	    {
32 	      errno = e;
33 	      return (name == _PC_NAME_MAX) ? name_max : path_max;
34 	    }
35 	}
36       return (name == _PC_NAME_MAX) ? NAME_MAX : PATH_MAX;
37     }
38   case _PC_PIPE_BUF:		return PIPE_BUF;
39   case _PC_CHOWN_RESTRICTED:	return _POSIX_CHOWN_RESTRICTED;
40   case _PC_NO_TRUNC:		return _POSIX_NO_TRUNC;
41   case _PC_VDISABLE:		return _POSIX_VDISABLE;
42 
43   default:
44     errno = EINVAL;
45     return -1;
46   }
47 }
48