(root)/
acl-2.3.1/
libacl/
acl_init.c
       1  /*
       2    File: acl_init.c
       3  
       4    Copyright (C) 1999, 2000
       5    Andreas Gruenbacher, <andreas.gruenbacher@gmail.com>
       6  
       7    This program is free software; you can redistribute it and/or
       8    modify it under the terms of the GNU Lesser General Public
       9    License as published by the Free Software Foundation; either
      10    version 2.1 of the License, or (at your option) any later version.
      11  
      12    This program is distributed in the hope that it will be useful,
      13    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15    Lesser General Public License for more details.
      16  
      17    You should have received a copy of the GNU Lesser General Public
      18    License along with this library; if not, write to the Free Software
      19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
      20  */
      21  
      22  #include "config.h"
      23  #include "libacl.h"
      24  
      25  
      26  acl_obj *
      27  __acl_init_obj(int count)
      28  {
      29  	acl_obj *acl_obj_p = new_obj_p(acl);
      30  	if (!acl_obj_p)
      31  		return NULL;
      32  	acl_obj_p->aused = 0;
      33  	acl_obj_p->aprev = acl_obj_p->anext = (acl_entry_obj *)acl_obj_p;
      34  	acl_obj_p->acurr = (acl_entry_obj *)acl_obj_p;
      35  
      36  	/* aprealloc points to an array of pre-allocated ACL entries.
      37  	   Entries between [aprealloc, aprealloc_end) are still available.
      38  	   Pre-allocated entries are consumed from the last entry to the
      39  	   first and aprealloc_end decremented. After all pre-allocated
      40  	   entries are consumed, further entries are malloc'ed.
      41  	   aprealloc == aprealloc_end is true when no more pre-allocated	
      42  	   entries are available. */
      43  
      44  	if (count > 0)
      45  		acl_obj_p->aprealloc = (acl_entry_obj *)
      46  			malloc(count * sizeof(acl_entry_obj));
      47  	else
      48  		acl_obj_p->aprealloc = NULL;
      49  	if (acl_obj_p->aprealloc != NULL)
      50  		acl_obj_p->aprealloc_end = acl_obj_p->aprealloc + count;
      51  	else
      52  		acl_obj_p->aprealloc_end = NULL;
      53  
      54  	return acl_obj_p;
      55  }
      56  
      57  
      58  /* 23.4.20 */
      59  acl_t
      60  acl_init(int count)
      61  {
      62  	acl_obj *obj;
      63  	if (count < 0) {
      64  		errno = EINVAL;
      65  		return NULL;
      66  	}
      67  	obj = __acl_init_obj(count);
      68  	return int2ext(obj);
      69  }
      70