/*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 Lev Walkin . * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: sf_mem.h,v 1.2 2005/05/25 21:55:10 vlm Exp $ */ #ifndef __SF_MEM_H__ #define __SF_MEM_H__ #include #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ char *strndup(const char *, size_t num);/* strdup() num bytes from the string */ char *sf_strdup(const char *); /* safe strdup() */ void *sf_malloc(size_t); /* safe malloc() */ void *sf_calloc(size_t, size_t); /* safe calloc() */ void *sf_realloc(void *, size_t); /* safe realloc() */ /********************************/ /*** LibStrfunc control flags ***/ /********************************/ #define SF_GET_MEMORY_FAILURE_BEHAVIOR 1 #define SF_SET_MEMORY_FAILURE_BEHAVIOR 2 #define SF_ARG_MFB_ABORT 0 /* Default is to call abort() */ #define SF_ARG_MFB_ENOMEM 1 /* Just return ENOMEM */ #define SF_ARG_MFB_TRY_ABORT 2 /* Try several times, then abort */ #define SF_ARG_MFB_TRY_ENOMEM 3 /* Try several times, then ENOMEM */ #define SF_ARG_MFB_TRY_NOFAIL 4 /* Try forever */ #define SF_GET_MEMORY_FAILURE_TRIES 3 /* Default: 10 try times */ #define SF_SET_MEMORY_FAILURE_TRIES 4 /* * Use these if you want to quickly do huge amount of strtotime(). * Will omit the time() system call on each call. */ #define SF_GET_STRTOTIME_ZINFO_CACHING 5 /* Default: 0 */ #define SF_SET_STRTOTIME_ZINFO_CACHING 6 int strfunc_ctl(int request, int *optArg); /* * Set a callback to be invoked upon memory failure. */ void strfunc_memory_failure_callback(void (*cb)(void)); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __SF_MEM_H__ */