1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)access_.c 5.1 06/07/85 7 */ 8 9 /* 10 * determine accessability of a file 11 * 12 * calling format: 13 * integer access 14 * ierror = access(filename, mode) 15 * where: 16 * ierror will be 0 for successful access; an error number otherwise. 17 * filename is a character string 18 * mode is a character string which may include any combination of 19 * 'r', 'w', 'x', ' '. (' ' => test for existence) 20 */ 21 22 #include "../libI77/f_errno.h" 23 #include <sys/param.h> 24 #ifndef MAXPATHLEN 25 #define MAXPATHLEN 128 26 #endif 27 28 long access_(name, mode, namlen, modlen) 29 char *name, *mode; 30 long namlen, modlen; 31 { 32 char buf[MAXPATHLEN]; 33 int m = 0; 34 35 if (namlen >= sizeof buf) 36 return((long)(errno=F_ERARG)); 37 g_char(name, namlen, buf); 38 if (buf[0] == '\0') 39 return((long)(errno=ENOENT)); 40 if (access(buf, 0) < 0) 41 return((long)errno); 42 while (modlen--) switch(*mode++) 43 { 44 case 'x': 45 m |= 1; 46 break; 47 48 case 'w': 49 m |= 2; 50 break; 51 52 case 'r': 53 m |= 4; 54 break; 55 } 56 if (m > 0 && access(buf, m) < 0) 57 return((long)errno); 58 return(0L); 59 } 60