1 /*
2  * $Id: pstdlib.h,v 1.1 2005-09-18 22:05:31 dhmunro Exp $
3  * portability layer basic memory management interface
4  */
5 /* Copyright (c) 2005, The Regents of the University of California.
6  * All rights reserved.
7  * This file is part of yorick (http://yorick.sourceforge.net).
8  * Read the accompanying LICENSE file for details.
9  */
10 
11 #include <stdlib.h>
12 
13 #include "plugin.h"
14 
15 BEGIN_EXTERN_C
16 
17 PLUG_API void *(*p_malloc)(size_t);
18 PLUG_API void  (*p_free)(void *);
19 PLUG_API void *(*p_realloc)(void *, size_t);
20 
21 /* above data loaded to system malloc, free, and realloc
22  * -- call p_mminit to get mm version
23  */
24 #ifdef P_DEBUG
25 #define p_mminit p_mmdebug
26 PLUG2_API int p_mmcheck(void *p);
27 PLUG2_API void p_mmguard(void *b, unsigned long n);
28 PLUG2_API long p_mmextra, p_mmoffset;
29 #endif
30 PLUG_API void p_mminit(void);
31 
32 /* make trivial memory statistics globally available
33  * -- counts total number of allocations, frees, and
34  *    current number of large blocks */
35 PLUG_API long p_nallocs;
36 PLUG_API long p_nfrees;
37 PLUG_API long p_nsmall;
38 PLUG_API long p_asmall;
39 
40 /* define this to get control when mm functions fail
41  * -- if it returns, must return 0 */
42 PLUG_API void *(*p_mmfail)(unsigned long n);
43 
44 /* temporary space */
45 #define P_WKSIZ 2048
46 typedef union {
47   char c[P_WKSIZ+8];
48   int i[P_WKSIZ/8];
49   long l[P_WKSIZ/8];
50   double d[P_WKSIZ/8];
51 } p_twkspc;
52 PLUG_API p_twkspc p_wkspc;
53 
54 /* similar to the string.h functions, but p_malloc destination
55  * - 0 src is acceptable */
56 PLUG_API void *p_memcpy(const void *, size_t);
57 PLUG_API char *p_strcpy(const char *);
58 PLUG_API char *p_strncat(const char *, const char *, size_t);
59 
60 /* expand leading env var, ~, set / or \ separators, free with p_free */
61 PLUG_API char *p_native(const char *unix_name);
62 
63 /* dont do anything critical if this is set -- signal an error */
64 PLUG2_API volatile int p_signalling;
65 
66 /* dynamic linking interface
67  * dlname is filename not including .so, .dll, .dylib, etc. suffix
68  * symbol is name in a C program
69  * type is 0 if expecting a function, 1 if expecting data
70  * paddr is &addr where addr is void* or void(*)(),
71  * p_dlsym return value is 0 on success, 1 on failure */
72 PLUG_API void *p_dlopen(const char *dlname);
73 PLUG_API int p_dlsym(void *handle, const char *symbol, int type, void *paddr);
74 
75 /* interface for synchronous subprocess
76  * (p_popen, p_spawn in pstdio.h for asynchronous)
77  */
78 PLUG_API int p_system(const char *cmdline);
79 
80 END_EXTERN_C
81