version 1.6, 2015/10/11 21:12:54 |
version 1.12, 2022/04/14 16:43:44 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
|
* Copyright (c) 2014, 2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> |
|
* |
* |
* 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 |
|
|
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
|
#if HAVE_ERR |
#include <err.h> |
#include <err.h> |
|
#endif |
#include <stdarg.h> |
#include <stdarg.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
|
|
|
#define DEBUG_NODEF 1 |
#include "mandoc.h" |
#include "mandoc.h" |
#include "mandoc_aux.h" |
#include "mandoc_aux.h" |
|
|
#if !HAVE_PROGNAME |
|
const char *mandoc_progname; |
|
#endif |
|
|
|
int |
int |
mandoc_asprintf(char **dest, const char *fmt, ...) |
mandoc_asprintf(char **dest, const char *fmt, ...) |
Line 72 mandoc_malloc(size_t size) |
|
Line 72 mandoc_malloc(size_t size) |
|
void * |
void * |
mandoc_realloc(void *ptr, size_t size) |
mandoc_realloc(void *ptr, size_t size) |
{ |
{ |
|
|
ptr = realloc(ptr, size); |
ptr = realloc(ptr, size); |
if (ptr == NULL) |
if (ptr == NULL) |
err((int)MANDOCLEVEL_SYSERR, NULL); |
err((int)MANDOCLEVEL_SYSERR, NULL); |
Line 82 mandoc_realloc(void *ptr, size_t size) |
|
Line 81 mandoc_realloc(void *ptr, size_t size) |
|
void * |
void * |
mandoc_reallocarray(void *ptr, size_t num, size_t size) |
mandoc_reallocarray(void *ptr, size_t num, size_t size) |
{ |
{ |
|
|
ptr = reallocarray(ptr, num, size); |
ptr = reallocarray(ptr, num, size); |
if (ptr == NULL) |
if (ptr == NULL) |
err((int)MANDOCLEVEL_SYSERR, NULL); |
err((int)MANDOCLEVEL_SYSERR, NULL); |
return ptr; |
return ptr; |
} |
} |
|
|
|
void * |
|
mandoc_recallocarray(void *ptr, size_t oldnum, size_t num, size_t size) |
|
{ |
|
ptr = recallocarray(ptr, oldnum, num, size); |
|
if (ptr == NULL) |
|
err((int)MANDOCLEVEL_SYSERR, NULL); |
|
return ptr; |
|
} |
|
|
char * |
char * |
mandoc_strdup(const char *ptr) |
mandoc_strdup(const char *ptr) |
{ |
{ |
char *p; |
char *p; |
|
|
p = strdup(ptr); |
p = strdup(ptr); |
if (ptr == NULL) |
if (p == NULL) |
err((int)MANDOCLEVEL_SYSERR, NULL); |
err((int)MANDOCLEVEL_SYSERR, NULL); |
return p; |
return p; |
} |
} |
Line 105 mandoc_strndup(const char *ptr, size_t sz) |
|
Line 112 mandoc_strndup(const char *ptr, size_t sz) |
|
{ |
{ |
char *p; |
char *p; |
|
|
p = mandoc_malloc(sz + 1); |
p = strndup(ptr, sz); |
memcpy(p, ptr, sz); |
if (p == NULL) |
p[(int)sz] = '\0'; |
err((int)MANDOCLEVEL_SYSERR, NULL); |
return p; |
return p; |
} |
} |