2 * Window Maker miscelaneous function library
4 * Copyright (c) 1997 Alfredo K. Kojima
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "../src/config.h"
27 #include <sys/types.h>
43 defaultHandler(int bla
)
52 static waborthandler
*aborthandler
= (waborthandler
*)defaultHandler
;
54 #define wAbort(a) (*aborthandler)(a)
58 wsetabort(waborthandler
*handler
)
60 waborthandler
*old
= aborthandler
;
62 aborthandler
= handler
;
69 static int Aborting
=0; /* if we're in the middle of an emergency exit */
72 static WMHashTable
*table
= NULL
;
75 void *wmalloc(size_t size
)
81 wwarning("malloc() failed. Retrying after 2s.");
86 puts("Real Bad Error: recursive malloc() failure.");
89 wfatal("virtual memory exhausted");
99 void *wrealloc(void *ptr
, size_t newsize
)
104 nptr
= malloc(newsize
);
106 nptr
=realloc(ptr
, newsize
);
109 printf("Could not do realloc");
122 table
= WMCreateHashTable(WMIntHashCallbacks
);
125 refcount
= WMHashGet(table
, ptr
);
127 refcount
= wmalloc(sizeof(int));
129 WMHashInsert(table
, ptr
, refcount
);
131 printf("== %i (%p)\n", *refcount
, ptr
);
136 printf("+ %i (%p)\n", *refcount
, ptr
);
149 refcount
= WMHashGet(table
, ptr
);
151 wwarning("trying to release unexisting data %p", ptr
);
156 printf("RELEASING %p\n", ptr
);
158 WMHashRemove(table
, ptr
);
164 printf("- %i (%p)\n", *refcount
, ptr
);
176 return strcpy(wmalloc(strlen(str
)+1), str
);
181 wstrappend(char *dst
, char *src
)
190 str
= wmalloc(strlen(dst
)+strlen(src
)+1);