File: faccess.c

package info (click to toggle)
netstd 3.07-2hamm.5
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 6,384 kB
  • ctags: 9,087
  • sloc: ansic: 72,547; cpp: 6,141; makefile: 1,681; yacc: 1,615; sh: 1,220; perl: 303; awk: 46
file content (44 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 *
 * faccess.c
 * Version 0.00.03
 * June 16, 1995
 * Copyright (C) 1995 Alexander O. Yuriev, CIS Laboratories, TEMPLE UNIVERSITY
 * GNU General Public License terms apply.
 * 
 * Modified by Olaf Kirch.
 */

#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>

#include "faccess.h"

int
iCheckAccess(pchFilename, uidOwner, gidOwner)
	char *pchFilename;
	uid_t uidOwner;
	gid_t gidOwner;
{
  struct stat statData;
  int status = FACCESSOK;
  
  if (stat(pchFilename,&statData) == -1) {
      if (errno == ENOENT)
        status = FACCESSNOTFOUND;
      else status = FACCESSIOERR;
  } else {
       if ((statData.st_mode & S_IWOTH) ||
  	   (statData.st_mode & S_IWGRP) ||
  	   ((statData.st_uid != uidOwner) && (statData.st_mode & S_IWUSR))) {
  	     status = FACCESSWRITABLE;
       } else if ((statData.st_uid != uidOwner) ||
       		(statData.st_gid != gidOwner)) {
       	     status = FACCESSBADOWNER;
       } else if ((statData.st_mode & S_IROTH)) {
	     status = FACCESSWARN;
       }
  }
  return status;
}