diff options
author | mongo <mongo@iomega> | 2016-04-15 16:20:17 -0300 |
---|---|---|
committer | mongo <mongo@iomega> | 2016-04-15 16:20:17 -0300 |
commit | f686ba184e0af3fd37aa8a743631a7a376f30843 (patch) | |
tree | e9a48dc691511a2961f93163944ba0ca1a84e5b3 /src/xmalloc.c | |
parent | c0a088d7a4bc61e6e69fa5bd8964c39f68507c71 (diff) |
Renamed src.scim2 to src
Diffstat (limited to 'src/xmalloc.c')
-rwxr-xr-x | src/xmalloc.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/xmalloc.c b/src/xmalloc.c new file mode 100755 index 0000000..becbeff --- /dev/null +++ b/src/xmalloc.c @@ -0,0 +1,55 @@ +#include <ncursesw/curses.h> +#include <stdlib.h> +#include "sc.h" +#include "xmalloc.h" +#include "macros.h" +#include "color.h" +#include "conf.h" + +extern void free(); +extern void exit(); + +#define MAGIC ((double) 1234567890.12344) + +char * scxmalloc(unsigned n) { + //register char *ptr; + //if ((ptr = malloc(n + sizeof(double))) == NULL) fatal("scxmalloc: no memory"); + //*((double *) ptr) = MAGIC; + //return(ptr + sizeof(double)); + + register char *ptr; + ptr = (char *) malloc(n); + if (ptr == NULL) fatal("scxmalloc: no memory"); + return (ptr); +} + +/* we make sure realloc will do a malloc if needed */ +char * scxrealloc(char *ptr, unsigned n) { + //if (ptr == NULL) return(scxmalloc(n)); + //ptr -= sizeof(double); + //if (*((double *) ptr) != MAGIC) fatal("scxrealloc: storage not scxmalloc'ed"); + //if ((ptr = realloc(ptr, n + sizeof(double))) == NULL) fatal("scxmalloc: no memory"); + //*((double *) ptr) = MAGIC; + //return(ptr + sizeof(double)); + + if (ptr == NULL) return(scxmalloc(n)); + ptr = (char *) realloc(ptr, n); + if (ptr == NULL) fatal("scxmalloc: no memory"); + return(ptr); +} + +void scxfree(char *p) { + //if (p == NULL) fatal("scxfree: NULL"); + //p -= sizeof(double); + //if (*((double *) p) != MAGIC) fatal("scxfree: storage not malloc'ed"); + //free(p); + + if (p == NULL) fatal("scxfree: NULL"); + free(p); +} + +void fatal(char * str) { + //fprintf(stderr,"%s\n", str); + //exit(1); + sc_error("%s", str); +} |