Detect FPU by checking CPUID features.
[dragonfly.git] / contrib / bind-9.5.2 / lib / isc / unix / fsaccess.c
bloba2bd89ad71317db721f4badc568c58ea399697a0
1 /*
2 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: fsaccess.c,v 1.13 2007/06/19 23:47:18 tbox Exp $ */
20 #include <config.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
25 #include <errno.h>
27 #include "errno2result.h"
29 /*! \file
30 * \brief
31 * The OS-independent part of the API is in lib/isc.
33 #include "../fsaccess.c"
35 isc_result_t
36 isc_fsaccess_set(const char *path, isc_fsaccess_t access) {
37 struct stat statb;
38 mode_t mode;
39 isc_boolean_t is_dir = ISC_FALSE;
40 isc_fsaccess_t bits;
41 isc_result_t result;
43 if (stat(path, &statb) != 0)
44 return (isc__errno2result(errno));
46 if ((statb.st_mode & S_IFDIR) != 0)
47 is_dir = ISC_TRUE;
48 else if ((statb.st_mode & S_IFREG) == 0)
49 return (ISC_R_INVALIDFILE);
51 result = check_bad_bits(access, is_dir);
52 if (result != ISC_R_SUCCESS)
53 return (result);
56 * Done with checking bad bits. Set mode_t.
58 mode = 0;
60 #define SET_AND_CLEAR1(modebit) \
61 if ((access & bits) != 0) { \
62 mode |= modebit; \
63 access &= ~bits; \
65 #define SET_AND_CLEAR(user, group, other) \
66 SET_AND_CLEAR1(user); \
67 bits <<= STEP; \
68 SET_AND_CLEAR1(group); \
69 bits <<= STEP; \
70 SET_AND_CLEAR1(other);
72 bits = ISC_FSACCESS_READ | ISC_FSACCESS_LISTDIRECTORY;
74 SET_AND_CLEAR(S_IRUSR, S_IRGRP, S_IROTH);
76 bits = ISC_FSACCESS_WRITE |
77 ISC_FSACCESS_CREATECHILD |
78 ISC_FSACCESS_DELETECHILD;
80 SET_AND_CLEAR(S_IWUSR, S_IWGRP, S_IWOTH);
82 bits = ISC_FSACCESS_EXECUTE |
83 ISC_FSACCESS_ACCESSCHILD;
85 SET_AND_CLEAR(S_IXUSR, S_IXGRP, S_IXOTH);
87 INSIST(access == 0);
89 if (chmod(path, mode) < 0)
90 return (isc__errno2result(errno));
92 return (ISC_R_SUCCESS);