resetting manifest requested domain to floor
[platform/upstream/acl.git] / libacl / __libobj.c
1 /*
2   File: __libobj.c
3   (Linux Access Control List Management)
4
5   Copyright (C) 1999-2002
6   Andreas Gruenbacher, <a.gruenbacher@bestbits.at>
7         
8   This program is free software; you can redistribute it and/or
9   modify it under the terms of the GNU Lesser General Public
10   License as published by the Free Software Foundation; either
11   version 2.1 of the License, or (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16   Lesser General Public License for more details.
17
18   You should have received a copy of the GNU Lesser General Public
19   License along with this library; if not, write to the Free Software
20   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 #include <errno.h>
24 #include <stdlib.h>
25 #include "libobj.h"
26
27 #ifdef LIBACL_DEBUG
28 # include <stdio.h>
29 #endif
30
31 /* object creation, destruction, conversion and validation */
32
33 void *
34 __new_var_obj_p(int magic, size_t size)
35 {
36         obj_prefix *obj_p = (obj_prefix *)malloc(size);
37         if (obj_p) {
38                 obj_p->p_magic = (long)magic;
39                 obj_p->p_flags = OBJ_MALLOC_FLAG;
40         }
41         return obj_p;
42 }
43
44
45 void
46 __new_obj_p_here(int magic, void *here)
47 {
48         obj_prefix *obj_p = here;
49         obj_p->p_magic = (long)magic;
50         obj_p->p_flags = 0;
51 }
52
53
54 void
55 __free_obj_p(obj_prefix *obj_p)
56 {
57         obj_p->p_magic = 0;
58         if (obj_p->p_flags & OBJ_MALLOC_FLAG)
59                 free(obj_p);
60 }
61
62
63 obj_prefix *
64 __check_obj_p(obj_prefix *obj_p, int magic)
65 {
66         if (!obj_p || obj_p->p_magic != (long)magic) {
67                 errno = EINVAL;
68                 return NULL;
69         }
70         return obj_p;
71 }
72
73
74 #ifdef LIBACL_DEBUG
75 obj_prefix *
76 __ext2int_and_check(void *ext_p, int magic, const char *typename)
77 #else
78 obj_prefix *
79 __ext2int_and_check(void *ext_p, int magic)
80 #endif
81 {
82         obj_prefix *obj_p = ((obj_prefix *)ext_p)-1;
83         if (!ext_p) {
84 #ifdef LIBACL_DEBUG
85                 fprintf(stderr, "invalid %s object at %p\n",
86                         typename, obj_p);
87 #endif
88                 errno = EINVAL;
89                 return NULL;
90         }
91         return __check_obj_p(obj_p, magic);
92 }
93