X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fdoalloc.c;h=e3b1a2e96c1bf378f2c0f70c8110762187ecfbb5;hp=84471fb6b20cc56df746b7712af3e38f7ea657c3;hb=312665d3aaaf5d8e3ba34d80fdd650abf758272a;hpb=0eb88fc5281804773e2a0c7a488a4452463535ce diff --git a/ncurses/tinfo/doalloc.c b/ncurses/tinfo/doalloc.c index 84471fb6..e3b1a2e9 100644 --- a/ncurses/tinfo/doalloc.c +++ b/ncurses/tinfo/doalloc.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998 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 * @@ -30,7 +31,6 @@ * Author: Thomas E. Dickey 1998 * ****************************************************************************/ - /* * Wrapper for malloc/realloc. Standard implementations allow realloc with * a null pointer, but older libraries may not (e.g., SunOS). @@ -40,35 +40,23 @@ #include -MODULE_ID("$Id: doalloc.c,v 1.5 1999/03/14 12:25:27 tom Exp $") - -void *_nc_doalloc(void *oldp, size_t amount) -{ - void *newp; - - if (oldp != 0) { - if ((newp = realloc(oldp, amount)) == 0) { - free(oldp); - errno = ENOMEM; /* just in case 'free' reset */ - } - } else { - newp = typeMalloc(char, amount); - } - return newp; -} +MODULE_ID("$Id: doalloc.c,v 1.14 2021/04/24 23:43:39 tom Exp $") -#if !HAVE_STRDUP -char *_nc_strdup(const char *src) +void * +_nc_doalloc(void *oldp, size_t amount) { - char *dst; - if (src != 0) { - dst = typeMalloc(char, strlen(src) + 1); - if (dst != 0) { - (void)strcpy(dst, src); + void *newp; + + 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 */ } } else { - dst = 0; + newp = malloc(amount); } - return dst; + return newp; } -#endif