/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * Copyright 2020,2021 Thomas E. Dickey *
+ * Copyright 1998-2002,2012 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
#include <curses.priv.h>
-MODULE_ID("$Id: doalloc.c,v 1.8 2002/08/31 21:48:11 Philippe.Blain Exp $")
+MODULE_ID("$Id: doalloc.c,v 1.14 2021/04/24 23:43:39 tom Exp $")
-NCURSES_EXPORT(void *)
+void *
_nc_doalloc(void *oldp, size_t amount)
{
void *newp;
- if (oldp != 0) {
- if ((newp = realloc(oldp, amount)) == 0) {
+ if (oldp != NULL) {
+ if (amount == 0) {
+ free(oldp);
+ newp = NULL;
+ } else if ((newp = realloc(oldp, amount)) == 0) {
free(oldp);
errno = ENOMEM; /* just in case 'free' reset */
}
}
return newp;
}
-
-#if !HAVE_STRDUP
-NCURSES_EXPORT(char *)
-_nc_strdup(const char *src)
-{
- char *dst;
- if (src != 0) {
- dst = typeMalloc(char, strlen(src) + 1);
- if (dst != 0) {
- (void) strcpy(dst, src);
- }
- } else {
- dst = 0;
- }
- return dst;
-}
-#endif