1 2 #include "pl-incl.h" 3 4 5 /******************************** 6 * STRINGS * 7 *********************************/ 8 9 10 #ifdef O_DEBUG 11 #define CHAR_INUSE 0x42 12 #define CHAR_FREED 0x41 13 14 char * store_string(const char * s)15store_string(const char *s) 16 { if ( s ) 17 { GET_LD 18 char *copy = (char *)allocHeap(strlen(s)+2); 19 20 *copy++ = CHAR_INUSE; 21 strcpy(copy, s); 22 23 return copy; 24 } else 25 { return NULL; 26 } 27 } 28 29 30 void remove_string(char * s)31remove_string(char *s) 32 { if ( s ) 33 { GET_LD 34 assert(s[-1] == CHAR_INUSE); 35 36 s[-1] = CHAR_FREED; 37 freeHeap(s-1, strlen(s)+2); 38 } 39 } 40 41 #else /*O_DEBUG*/ 42 43 char * store_string(const char * s)44store_string(const char *s) 45 { if ( s ) 46 { GET_LD 47 48 char *copy = (char *)allocHeap(strlen(s)+1); 49 50 strcpy(copy, s); 51 return copy; 52 } else 53 { return NULL; 54 } 55 } 56 57 58 void remove_string(char * s)59remove_string(char *s) 60 { if ( s ) 61 { GET_LD 62 freeHeap(s, strlen(s)+1); 63 } 64 } 65 66 #endif /*O_DEBUG*/ 67 68