home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / security / freenav / secport.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.6 KB  |  137 lines

  1. /*
  2.  * The contents of this file are subject to the Netscape Public License
  3.  * Version 1.0 (the "NPL"); you may not use this file except in
  4.  * compliance with the NPL.  You may obtain a copy of the NPL at
  5.  * http://www.mozilla.org/NPL/
  6.  *
  7.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  8.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  9.  * for the specific language governing rights and limitations under the
  10.  * NPL.
  11.  *
  12.  * The Initial Developer of this code under the NPL is Netscape
  13.  * Communications Corporation.  Portions created by Netscape are
  14.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  15.  * Reserved.
  16.  */
  17.  
  18. #include "seccomon.h"
  19. #include "prmem.h"
  20. #include "prerror.h"
  21. #include "plarena.h"
  22. #include "prlog.h"
  23.  
  24. void *
  25. PORT_Alloc(size_t bytes)
  26. {
  27.     void *rv;
  28.  
  29.     /* Always allocate a non-zero amount of bytes */
  30.     rv = (void *)PR_Malloc(bytes ? bytes : 1);
  31.     return rv;
  32. }
  33.  
  34. void *
  35. PORT_Realloc(void *oldptr, size_t bytes)
  36. {
  37.     void *rv;
  38.  
  39.     rv = (void *)PR_Realloc(oldptr, bytes);
  40.     return rv;
  41. }
  42.  
  43. void *
  44. PORT_ZAlloc(size_t bytes)
  45. {
  46.     void *rv;
  47.  
  48.     /* Always allocate a non-zero amount of bytes */
  49.     rv = (void *)PR_Calloc(1, bytes ? bytes : 1);
  50.     return rv;
  51. }
  52.  
  53. void
  54. PORT_Free(void *ptr)
  55. {
  56.     if (ptr) {
  57.     PR_Free(ptr);
  58.     }
  59. }
  60.  
  61. void
  62. PORT_ZFree(void *ptr, size_t len)
  63. {
  64.     if (ptr) {
  65.     memset(ptr, 0, len);
  66.     PR_Free(ptr);
  67.     }
  68. }
  69.  
  70. PRArenaPool *
  71. PORT_NewArena(unsigned long chunksize)
  72. {
  73.     PRArenaPool *arena;
  74.     
  75.     arena = PORT_ZAlloc(sizeof(PRArenaPool));
  76.     if ( arena != NULL ) {
  77.     PR_InitArenaPool(arena, "security", chunksize, sizeof(double));
  78.     }
  79.  
  80.     return(arena);
  81. }
  82.  
  83. void *
  84. PORT_ArenaAlloc(PRArenaPool *arena, size_t size)
  85. {
  86.     void *p;
  87.  
  88.     PR_ARENA_ALLOCATE(p, arena, size);
  89.  
  90.     return(p);
  91. }
  92.  
  93. void *
  94. PORT_ArenaZAlloc(PRArenaPool *arena, size_t size)
  95. {
  96.     void *p;
  97.  
  98.     PR_ARENA_ALLOCATE(p, arena, size);
  99.     if (p == NULL) {
  100.     } else {
  101.     memset(p, 0, size);
  102.     }
  103.  
  104.     return(p);
  105. }
  106.  
  107. /* XXX - need to zeroize!! - jsw */
  108. void
  109. PORT_FreeArena(PRArenaPool *arena, PRBool zero)
  110. {
  111.     PR_FinishArenaPool(arena);
  112.     PORT_Free(arena);
  113. }
  114.  
  115. void *
  116. PORT_ArenaGrow(PRArenaPool *arena, void *ptr, size_t oldsize, size_t newsize)
  117. {
  118.     PR_ASSERT(newsize >= oldsize);
  119.     
  120.     PR_ARENA_GROW(ptr, arena, oldsize, ( newsize - oldsize ) );
  121.     
  122.     return(ptr);
  123. }
  124.  
  125. void *
  126. PORT_ArenaMark(PRArenaPool *arena)
  127. {
  128.     return PR_ARENA_MARK(arena);
  129. }
  130.  
  131. void
  132. PORT_ArenaRelease(PRArenaPool *arena, void *mark)
  133. {
  134.     PR_ARENA_RELEASE(arena, mark);
  135. }
  136.  
  137.