source: Sophya/trunk/SophyaLib/UnixMac/src/access.c@ 4066

Last change on this file since 4066 was 683, checked in by ansari, 26 years ago

Compilation Mac pour CodeWarrior PRO 5

File size: 821 bytes
Line 
1/* $Id: access.c,v 1.1 1999-12-10 17:11:18 ansari Exp $ */
2
3#include <string.h>
4#include <errno.h>
5#include "unixmac.h"
6
7/*
8 * If mode includes check for write permission,
9 * and file is locked, return -1 (failure).
10 */
11
12#define LOCKBIT 0x1
13
14int
15access(char* path, int mode)
16{
17 CInfoPBRec cipbr;
18 HFileInfo *fpb = (HFileInfo*)&cipbr;
19 DirInfo *dpb = (DirInfo*)&cipbr;
20 short err;
21 char name[FILENAME_MAX];
22
23 strncpy(name, path, sizeof(name)-1);
24 c2pstr(name);
25 dpb->ioDrDirID= 0L;
26 fpb->ioNamePtr= (unsigned char*)name;
27 fpb->ioVRefNum= 0;
28 fpb->ioFDirIndex= 0;
29 fpb->ioFVersNum= 0;
30 err= PBGetCatInfo(&cipbr, FALSE);
31 if (err != noErr) {
32 errno = ENOENT;
33 return -1;
34 }
35 /* check for write-permission = not locked */
36 if ((mode & 02) && (fpb->ioFlAttrib & LOCKBIT)) {
37 errno = EACCES;
38 return -1;
39 }
40 return 0;
41}
42
Note: See TracBrowser for help on using the repository browser.