(root)/
acl-2.3.1/
libacl/
__libobj.c
       1  /*
       2    File: __libobj.c
       3    (Linux Access Control List Management)
       4  
       5    Copyright (C) 1999-2002
       6    Andreas Gruenbacher, <andreas.gruenbacher@gmail.com>
       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 "config.h"
      24  #include <errno.h>
      25  #include <stdlib.h>
      26  #include "libobj.h"
      27  
      28  #ifdef LIBACL_DEBUG
      29  # include <stdio.h>
      30  #endif
      31  
      32  /* object creation, destruction, conversion and validation */
      33  
      34  void *
      35  __new_var_obj_p(int magic, size_t size)
      36  {
      37  	obj_prefix *obj_p = (obj_prefix *)malloc(size);
      38  	if (obj_p) {
      39  		obj_p->p_magic = (long)magic;
      40  		obj_p->p_flags = OBJ_MALLOC_FLAG;
      41  	}
      42  	return obj_p;
      43  }
      44  
      45  
      46  void
      47  __new_obj_p_here(int magic, void *here)
      48  {
      49  	obj_prefix *obj_p = here;
      50  	obj_p->p_magic = (long)magic;
      51  	obj_p->p_flags = 0;
      52  }
      53  
      54  
      55  void
      56  __free_obj_p(obj_prefix *obj_p)
      57  {
      58  	obj_p->p_magic = 0;
      59  	if (obj_p->p_flags & OBJ_MALLOC_FLAG)
      60  		free(obj_p);
      61  }
      62  
      63  
      64  obj_prefix *
      65  __check_obj_p(obj_prefix *obj_p, int magic)
      66  {
      67  	if (!obj_p || obj_p->p_magic != (long)magic) {
      68  		errno = EINVAL;
      69  		return NULL;
      70  	}
      71  	return obj_p;
      72  }
      73  
      74  
      75  #ifdef LIBACL_DEBUG
      76  obj_prefix *
      77  __ext2int_and_check(void *ext_p, int magic, const char *typename)
      78  #else
      79  obj_prefix *
      80  __ext2int_and_check(void *ext_p, int magic)
      81  #endif
      82  {
      83  	obj_prefix *obj_p = ((obj_prefix *)ext_p)-1;
      84  	if (!ext_p) {
      85  #ifdef LIBACL_DEBUG
      86  		fprintf(stderr, "invalid %s object at %p\n",
      87  		        typename, obj_p);
      88  #endif
      89  		errno = EINVAL;
      90  		return NULL;
      91  	}
      92  	return __check_obj_p(obj_p, magic);
      93  }
      94