Print this page
9718 update mandoc to 1.14.4
   1 /*      $Id: mandoc_aux.c,v 1.10 2017/06/12 19:05:47 schwarze Exp $ */
   2 /*
   3  * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4  * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
   5  *
   6  * Permission to use, copy, modify, and distribute this software for any
   7  * purpose with or without fee is hereby granted, provided that the above
   8  * copyright notice and this permission notice appear in all copies.
   9  *
  10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
  11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17  */
  18 #include "config.h"
  19 
  20 #include <sys/types.h>
  21 


  94                 err((int)MANDOCLEVEL_SYSERR, NULL);
  95         return ptr;
  96 }
  97 
  98 char *
  99 mandoc_strdup(const char *ptr)
 100 {
 101         char    *p;
 102 
 103         p = strdup(ptr);
 104         if (p == NULL)
 105                 err((int)MANDOCLEVEL_SYSERR, NULL);
 106         return p;
 107 }
 108 
 109 char *
 110 mandoc_strndup(const char *ptr, size_t sz)
 111 {
 112         char    *p;
 113 
 114         p = mandoc_malloc(sz + 1);
 115         memcpy(p, ptr, sz);
 116         p[(int)sz] = '\0';
 117         return p;
 118 }
   1 /*      $Id: mandoc_aux.c,v 1.11 2018/02/07 20:04:57 schwarze Exp $ */
   2 /*
   3  * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
   4  * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
   5  *
   6  * Permission to use, copy, modify, and distribute this software for any
   7  * purpose with or without fee is hereby granted, provided that the above
   8  * copyright notice and this permission notice appear in all copies.
   9  *
  10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
  11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
  13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17  */
  18 #include "config.h"
  19 
  20 #include <sys/types.h>
  21 


  94                 err((int)MANDOCLEVEL_SYSERR, NULL);
  95         return ptr;
  96 }
  97 
  98 char *
  99 mandoc_strdup(const char *ptr)
 100 {
 101         char    *p;
 102 
 103         p = strdup(ptr);
 104         if (p == NULL)
 105                 err((int)MANDOCLEVEL_SYSERR, NULL);
 106         return p;
 107 }
 108 
 109 char *
 110 mandoc_strndup(const char *ptr, size_t sz)
 111 {
 112         char    *p;
 113 
 114         p = strndup(ptr, sz);
 115         if (p == NULL)
 116                 err((int)MANDOCLEVEL_SYSERR, NULL);
 117         return p;
 118 }