summaryrefslogtreecommitdiff
path: root/generic
diff options
context:
space:
mode:
authorPixel <Pixel>2002-08-18 01:38:23 +0000
committerPixel <Pixel>2002-08-18 01:38:23 +0000
commit396239cc78a75ba7be739788485319c92b07d827 (patch)
treecd3e9ef485c1026e40b909c1989ef662cde30f5f /generic
parent11bf45f50739afb923829b3cc32efb9c8c009613 (diff)
Blehaurg
Diffstat (limited to 'generic')
-rw-r--r--generic/Exceptions.cpp20
-rw-r--r--generic/Handle.cpp14
-rw-r--r--generic/Input.cpp2
-rw-r--r--generic/String.cpp6
4 files changed, 27 insertions, 15 deletions
diff --git a/generic/Exceptions.cpp b/generic/Exceptions.cpp
index 564362e..f24c0fb 100644
--- a/generic/Exceptions.cpp
+++ b/generic/Exceptions.cpp
@@ -82,15 +82,16 @@ void * xmalloc(size_t s) throw (GeneralException) {
return 0;
}
- if (!(r = (char *) ::malloc(s + sizeof(size_t)))) {
- throw MemoryException(s + sizeof(size_t));
+ if (!(r = (char *) ::malloc(s + 2 * sizeof(size_t)))) {
+ throw MemoryException(s + 2 * sizeof(size_t));
}
- memset(r, 0, s + sizeof(size_t));
+ memset(r, 0, s + 2 * sizeof(size_t));
*((size_t *)r) = s;
+ *(((size_t *)r) + 1) = 0xdeedbeef;
- return (void *)(r + sizeof(size_t));
+ return (void *)(r + 2 * sizeof(size_t));
}
void * xrealloc(void * ptr, size_t s) {
@@ -118,15 +119,16 @@ void * xrealloc(void * ptr, size_t s) {
#endif
void xfree(void *& p) {
- if (p) {
- ::free(((char *)p) - sizeof(size_t));
- p = 0;
- }
+ xfree(((char *)p));
}
void xfree(char *& p) {
if (p) {
- ::free(p - sizeof(size_t));
+ if (*(((size_t *)p) - 1) != 0xdeedbeef) {
+ fprintf(stderr, "Error: trying to xfree() a non xmalloc()ed bloc.\n");
+ exit(-1);
+ }
+ ::free(p - 2 * sizeof(size_t));
p = 0;
}
}
diff --git a/generic/Handle.cpp b/generic/Handle.cpp
index 44b01de..e95a28a 100644
--- a/generic/Handle.cpp
+++ b/generic/Handle.cpp
@@ -297,3 +297,17 @@ bool Handle::CanSeek() {
off_t Handle::seek(off_t, int) throw(GeneralException) {
throw IOGeneral("Handle " + GetName() + " can't seek");
}
+
+void copy(Handle * s, Handle * d, ssize_t size) {
+ long i;
+ unsigned char c;
+ long r;
+
+ for (i = 0; (i < size) || (size < 0); i++) {
+ r = s->read(&c, 1);
+ if (r == 0) {
+ break;
+ }
+ d->write(&c, 1);
+ }
+}
diff --git a/generic/Input.cpp b/generic/Input.cpp
index a51ee65..b7ee99c 100644
--- a/generic/Input.cpp
+++ b/generic/Input.cpp
@@ -13,7 +13,7 @@
#define _(x) x
#endif
-Input::Input(String no) throw (GeneralException) :
+Input::Input(const String & no) throw (GeneralException) :
Handle(no.strlen() ? open(no.to_charp(), O_RDONLY) : dup(0)),
n(no) {
if (GetHandle() < 0) {
diff --git a/generic/String.cpp b/generic/String.cpp
index 0f4da24..c389c13 100644
--- a/generic/String.cpp
+++ b/generic/String.cpp
@@ -23,17 +23,13 @@ String::String(char c) : siz(1) {
str = t;
}
-String::String(const char * s, ...) : str(s ? Base::strdup(s) : Base::strdup("")) {
+String::String(const char * s, ...) {
va_list ap;
- if (!s)
- return;
-
/* This causes a warning: cannot pass objects of type `const String' through `...'
but it is not really a problem. */
va_start(ap, s);
vsnprintf(t, BUFSIZ, s, ap);
- free(str);
str = Base::strdup(t);
va_end(ap);
siz = ::strlen(str);