|
|
coherent
notmem() General Function (libc) notmem()
Check if memory is allocated
iinntt nnoottmmeemm(_p_t_r);
cchhaarr *_p_t_r;
notmem checks if a memory block has been allocated by calloc,
malloc, or realloc. ptr points to the block to be checked.
notmem searches the arena for ptr. It returns one if ptr is not
a memory block obtained from malloc, calloc, or realloc, and zero
if it is.
***** Example *****
The following example prints a string, and frees it if it was
malloc'd.
#include <sys/malloc.h>
pfree(s)
char *s;
{
printf("%s\n", s);
if(!notmem(s))
free(s);
}
main()
{
char *mallocked_string;
char notmallocked_string[50];
if ((mallocked_string = malloc(50)) == NULL)
exit(1);
strcpy(mallocked_string, "This is a malloc'd string");
strcpy(notmallocked_string, "This is not a malloc'd string");
pfree(mallocked_string);
pfree(notmallocked_string);
}
COHERENT Lexicon Page 1
notmem() General Function (libc) notmem()
***** See Also *****
arena, calloc(), free(), general functions, malloc(), realloc(),
setbuf()
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.