[BACK]Return to compat_recallocarray.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/compat_recallocarray.c between version 1.1 and 1.2

version 1.1, 2017/06/12 19:05:47 version 1.2, 2020/06/15 01:37:15
Line 1 
Line 1 
 #include "config.h"  
   
 #if HAVE_RECALLOCARRAY  
   
 int dummy;  
   
 #else  
   
 /*      $Id$ */  /*      $Id$ */
 /*      $OpenBSD$ */  /*      $OpenBSD$       */
 /*  /*
  * Copyright (c) 2017 Otto Moerbeek <otto@drijf.net>   * Copyright (c) 2008, 2017 Otto Moerbeek <otto@drijf.net>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 23  int dummy;
Line 15  int dummy;
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include "config.h"
   
 #include <sys/types.h>  #include <sys/types.h>
 #include <errno.h>  #include <errno.h>
 #include <stdint.h>  
 #include <stdlib.h>  #include <stdlib.h>
   #include <stdint.h>
 #include <string.h>  #include <string.h>
   
 /*  /*
  * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX   * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
  * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW   * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
  */   */
 #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))  #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
   
 /*  /*
  * Even though specified in POSIX, the PAGESIZE and PAGE_SIZE   * Even though specified in POSIX, the PAGESIZE and PAGE_SIZE
Line 42  int dummy;
Line 35  int dummy;
  * to avoid free() overhead for small shrinking, simply pick   * to avoid free() overhead for small shrinking, simply pick
  * an arbitrary number.   * an arbitrary number.
  */   */
 #define MALLOC_PAGESIZE         (1UL << 12)  #define getpagesize()   (1UL << 12)
   
   
 void *  void *
Line 75  recallocarray(void *ptr, size_t oldnmemb, size_t newnm
Line 68  recallocarray(void *ptr, size_t oldnmemb, size_t newnm
         if (newsize <= oldsize) {          if (newsize <= oldsize) {
                 size_t d = oldsize - newsize;                  size_t d = oldsize - newsize;
   
                 if (d < oldsize / 2 && d < MALLOC_PAGESIZE) {                  if (d < oldsize / 2 && d < getpagesize()) {
                         memset((char *)ptr + newsize, 0, d);                          memset((char *)ptr + newsize, 0, d);
                         return ptr;                          return ptr;
                 }                  }
Line 104  recallocarray(void *ptr, size_t oldnmemb, size_t newnm
Line 97  recallocarray(void *ptr, size_t oldnmemb, size_t newnm
   
         return newptr;          return newptr;
 }  }
   
 #endif /* !HAVE_RECALLOCARRAY */  

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

CVSweb