t_pathconf.c revision 64562
1254219Scy/* 2254219Scy** The following test program tries the pathconf(2) routine. It should 3254219Scy** be run in a non-NFS-mounted directory (e.g., /tmp) and on remote (NFS) 4254219Scy** mounted directories running both NFS-v2 and NFS-v3 from systems that 5254219Scy** both do and do not permit file giveaway. 6254219Scy*/ 7254219Scy 8254219Scy#include <sys/types.h> 9254219Scy#include <errno.h> 10254219Scy#include <fcntl.h> 11254219Scy#include <stdio.h> 12254219Scy#include <unistd.h> 13254219Scy#ifdef EX_OK 14254219Scy# undef EX_OK /* unistd.h may have another use for this */ 15254219Scy#endif /* EX_OK */ 16254219Scy#include <sysexits.h> 17254219Scy 18254219Scy#ifndef lint 19254219Scystatic char id[] = "@(#)$Id: t_pathconf.c,v 8.5 1999/08/28 00:25:28 gshapiro Exp $"; 20254219Scy#endif /* ! lint */ 21254219Scy 22254219Scyint 23254219Scymain(argc, argv) 24254219Scy int argc; 25254219Scy char **argv; 26254219Scy{ 27254219Scy int fd; 28254219Scy int i; 29254219Scy char tbuf[100]; 30254219Scy extern int errno; 31254219Scy 32254219Scy if (geteuid() == 0) 33254219Scy { 34254219Scy printf("*** Run me as a non-root user! ***\n"); 35254219Scy exit(EX_USAGE); 36254219Scy } 37254219Scy 38254219Scy strcpy(tbuf, "TXXXXXX"); 39254219Scy fd = mkstemp(tbuf); 40254219Scy if (fd < 0) 41254219Scy { 42254219Scy printf("*** Could not create test file %s\n", tbuf); 43254219Scy exit(EX_CANTCREAT); 44254219Scy } 45254219Scy errno = 0; 46254219Scy i = pathconf(".", _PC_CHOWN_RESTRICTED); 47254219Scy printf("pathconf(.) returns %2d, errno = %d\n", i, errno); 48254219Scy errno = 0; 49254219Scy i = pathconf(tbuf, _PC_CHOWN_RESTRICTED); 50254219Scy printf("pathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno); 51254219Scy errno = 0; 52254219Scy i = fpathconf(fd, _PC_CHOWN_RESTRICTED); 53254219Scy printf("fpathconf(%s) returns %2d, errno = %d\n", tbuf, i, errno); 54254219Scy if (errno == 0 && i >= 0) 55254219Scy { 56254219Scy /* so it claims that it doesn't work -- try anyhow */ 57254219Scy printf(" fpathconf claims that chown is safe "); 58254219Scy if (fchown(fd, 1, 1) >= 0) 59254219Scy printf("*** but fchown works anyhow! ***\n"); 60254219Scy else 61254219Scy printf("and fchown agrees\n"); 62254219Scy } 63254219Scy else 64254219Scy { 65254219Scy /* well, let's see what really happens */ 66254219Scy printf(" fpathconf claims that chown is not safe "); 67254219Scy if (fchown(fd, 1, 1) >= 0) 68254219Scy printf("as indeed it is not\n"); 69254219Scy else 70254219Scy printf("*** but in fact it is safe ***\n"); 71254219Scy } 72254219Scy (void) unlink(tbuf); 73254219Scy exit(EX_OK); 74254219Scy} 75254219Scy