summaryrefslogtreecommitdiff
path: root/lib/Exceptions.cc
diff options
context:
space:
mode:
authorPixel <Pixel>2001-11-26 23:11:40 +0000
committerPixel <Pixel>2001-11-26 23:11:40 +0000
commit3baa9d168c02a8734b95d1cc467601b6aaf2f6e4 (patch)
tree6c254e9d75dee5a1e305283788fea3d3fff2a445 /lib/Exceptions.cc
parent3aa63fcbddbce8762ad0f3f54d90ad985c0f9c41 (diff)
Big job here. Many bugs out. Hurray!!
Diffstat (limited to 'lib/Exceptions.cc')
-rw-r--r--lib/Exceptions.cc55
1 files changed, 39 insertions, 16 deletions
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc
index 585b946..6e4ddbe 100644
--- a/lib/Exceptions.cc
+++ b/lib/Exceptions.cc
@@ -6,6 +6,7 @@
#include "config.h"
#include "String.h"
#include "Exceptions.h"
+#include "General.h"
char GeneralException::t[BUFSIZ];
@@ -60,35 +61,49 @@ TaskSwitch::TaskSwitch() : GeneralException(_("Switching task in a non-tasked en
#endif
}
-char * xstrdup(const char * s) throw (GeneralException) {
+char * xstrdup(const char * s) {
char * r;
- if (!(r = ::strdup(s))) {
- throw MemoryException(strlen(s + 1));
- }
-
+ r = (char *) xmalloc(strlen(s) + 1);
+ strcpy(r, s);
return r;
}
-void * xmalloc(ssize_t s) throw (GeneralException) {
- void * r;
+void * xmalloc(size_t s) throw (GeneralException) {
+ char * r;
+
+ if (!s) {
+ return 0;
+ }
- if (!(r = ::malloc(s))) {
- throw MemoryException(s);
+ if (!(r = (char *) ::malloc(s + sizeof(size_t)))) {
+ throw MemoryException(s + sizeof(size_t));
}
- memset(r, 0, s);
+ memset(r, 0, s + sizeof(size_t));
+
+ *((size_t *)r) = s;
- return r;
+ return (void *)(r + sizeof(size_t));
}
-void * xrealloc(void * ptr, size_t s) throw (GeneralException) {
- void * r;
+void * xrealloc(void * ptr, size_t s) {
+ char * r;
+ size_t os;
- if (!(r = ::realloc(ptr, s))) {
- throw MemoryException(s);
+ if (!ptr) {
+ return xmalloc(s);
}
+ os = *(((size_t *) ptr) - 1);
+
+ r = (char *) xmalloc(s);
+
+ if (s) {
+ memcpy(r, ptr, MIN(s, os));
+ }
+
+ xfree(ptr);
return r;
}
@@ -98,7 +113,15 @@ void * xrealloc(void * ptr, size_t s) throw (GeneralException) {
void xfree(void *& p) {
if (p) {
- ::free(p);
+ ::free(((char *)p) - sizeof(size_t));
p = 0;
}
}
+
+int xpipe(int * p, int flag) throw (GeneralException) {
+ if (pipe(p)) {
+ throw GeneralException(String("Error creating pipe: ") + strerror(errno));
+ }
+
+ return p[flag];
+}