X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=src%2Fcstack.c;h=610483e344ebf4d0e9000e12a7f789f1b10ae503;hb=01a21345277528bb331653603e0d3771e5ed5870;hp=4763b5b5c9b4e2e48860810499d07bc0061d310a;hpb=bdd26d4dde3b3d3180619cc81622081025ca6cb5;p=smdp.git diff --git a/src/cstack.c b/src/cstack.c index 4763b5b..610483e 100644 --- a/src/cstack.c +++ b/src/cstack.c @@ -1,6 +1,6 @@ /* * An implementation of a char stack in heap memory. - * Copyright (C) 2014 Michael Goehler + * Copyright (C) 2015 Michael Goehler * * This file is part of mdp. * @@ -19,6 +19,7 @@ * */ +#include #include // fprintf #include // malloc, realloc @@ -42,24 +43,24 @@ cstack_t *cstack_init() { return stack; } -void cstack_push(cstack_t *self, char c) { +void cstack_push(cstack_t *self, wchar_t c) { if(self->size + sizeof(c) > self->alloc) { - self->alloc += (sizeof(char)); + self->alloc += (sizeof(wchar_t)); if((self->content = realloc(self->content, self->alloc)) == NULL) { fprintf(stderr, "%s\n", "cstack_push() failed to reallocate memory."); exit(EXIT_FAILURE); } } self->content[++self->head] = c; - self->size += (sizeof(char)); + self->size += (sizeof(wchar_t)); } -char cstack_pop(cstack_t *self) { - self->size -= (sizeof(char)); +wchar_t cstack_pop(cstack_t *self) { + self->size -= (sizeof(wchar_t)); return self->content[self->head--]; } -bool cstack_top(cstack_t *self, char c) { +bool cstack_top(cstack_t *self, wchar_t c) { return self->head >= 0 && self->content[self->head] == c; }