xref: /minix/minix/lib/libc/sys/fpathconf.c (revision 7f5f010b)
1 /* POSIX fpathconf (Sec. 5.7.1) 		Author: Andy Tanenbaum */
2 
3 #include <sys/cdefs.h>
4 #include "namespace.h"
5 #include <lib.h>
6 
7 #include <sys/stat.h>
8 #include <errno.h>
9 #include <limits.h>
10 #include <unistd.h>
11 #include <termios.h>
12 
13 long fpathconf(fd, name)
14 int fd;				/* file descriptor being interrogated */
15 int name;			/* property being inspected */
16 {
17 /* POSIX allows some of the values in <limits.h> to be increased at
18  * run time.  The pathconf and fpathconf functions allow these values
19  * to be checked at run time.  MINIX does not use this facility.
20  * The run-time limits are those given in <limits.h>.
21  */
22 
23   struct stat stbuf;
24 
25   switch(name) {
26 	case _PC_LINK_MAX:
27 		/* Fstat the file.  If that fails, return -1. */
28 		if (fstat(fd, &stbuf) != 0) return(-1);
29 		if (S_ISDIR(stbuf.st_mode))
30 			return(1L);	/* no links to directories */
31 		else
32 			return( (long) LINK_MAX);
33 
34 	case _PC_MAX_CANON:
35 		return( (long) MAX_CANON);
36 
37 	case _PC_MAX_INPUT:
38 		return( (long) MAX_INPUT);
39 
40 	case _PC_NAME_MAX:
41 		return( (long) NAME_MAX);
42 
43 	case _PC_PATH_MAX:
44 		return( (long) PATH_MAX);
45 
46 	case _PC_PIPE_BUF:
47 		return( (long) PIPE_BUF);
48 
49 	case _PC_CHOWN_RESTRICTED:
50 		return( (long) _POSIX_CHOWN_RESTRICTED);
51 
52 	case _PC_NO_TRUNC:
53 		return( (long) _POSIX_NO_TRUNC);
54 
55 	case _PC_VDISABLE:
56 		return( (long) _POSIX_VDISABLE);
57 
58 	default:
59 		errno = EINVAL;
60 		return(-1);
61   }
62 }
63