summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-06-16 15:16:49 +0800
committerwens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-06-16 15:16:49 +0800
commitc16f23e758c7a14452484d32962d5bed5c22d75e (patch)
tree1babdcb496a726e4cd4565adf0170a40ef2e03b5 /common
parent27a7b80caaae56e5ee058e70f4b95c50f86b5b5d (diff)
downloadpttbbs-c16f23e758c7a14452484d32962d5bed5c22d75e.tar
pttbbs-c16f23e758c7a14452484d32962d5bed5c22d75e.tar.gz
pttbbs-c16f23e758c7a14452484d32962d5bed5c22d75e.tar.bz2
pttbbs-c16f23e758c7a14452484d32962d5bed5c22d75e.tar.lz
pttbbs-c16f23e758c7a14452484d32962d5bed5c22d75e.tar.xz
pttbbs-c16f23e758c7a14452484d32962d5bed5c22d75e.tar.zst
pttbbs-c16f23e758c7a14452484d32962d5bed5c22d75e.zip
Constant vector (initialized with reference to given data)
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4369 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'common')
-rw-r--r--common/sys/vector.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/common/sys/vector.c b/common/sys/vector.c
index e5ed9346..d2c7a565 100644
--- a/common/sys/vector.c
+++ b/common/sys/vector.c
@@ -14,6 +14,18 @@ Vector_init(struct Vector *self, const int size)
self->length = 0;
self->capacity = 0;
self->base = NULL;
+ self->constant = false;
+}
+
+void
+Vector_init_const(struct Vector *self, char * base, const int length, const int size)
+{
+ assert(size != 0);
+ self->size = size;
+ self->length = length;
+ self->capacity = 0;
+ self->base = base;
+ self->constant = true;
}
void
@@ -21,9 +33,10 @@ Vector_delete(struct Vector *self)
{
self->length = 0;
self->capacity = 0;
- if (self->base)
+ if (self->base && !self->constant)
free(self->base);
self->base = NULL;
+ self->constant = false;
}
void
@@ -43,6 +56,9 @@ void
Vector_resize(struct Vector *self, const int length)
{
int capacity = length * self->size;
+
+ assert(!self->constant);
+
#define MIN_CAPACITY 4096
if (capacity == 0) {
if (self->base)
@@ -70,6 +86,7 @@ Vector_resize(struct Vector *self, const int length)
void
Vector_add(struct Vector *self, const char *name)
{
+ assert(!self->constant);
Vector_resize(self, self->length+1);
strlcpy(self->base + self->size * self->length, name, self->size);
self->length++;
@@ -137,6 +154,7 @@ int
Vector_remove(struct Vector *self, const char *name)
{
int i;
+ assert(!self->constant);
for (i=0; i<self->length; i++)
if (strcasecmp(self->base + self->size * i, name) == 0) {
strlcpy(self->base + self->size * i,