summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zone.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/zone.h b/zone.h
index 8199bda..c2e033e 100644
--- a/zone.h
+++ b/zone.h
@@ -16,8 +16,15 @@ typedef struct {
ZoneFrame *tail, *here;
} Zone;
+typedef struct {
+ ZoneFrame *zf;
+ size_t length;
+} ZoneState;
+
void zn_free(Zone *z);
void zn_clear(Zone *z);
+void zn_save(Zone *z, ZoneState *m);
+void zn_load(Zone *z, ZoneState *m);
void *zn_alloc(Zone *z, size_t n);
void *zn_zf_alloc(Zone *z, ZoneFrame **zf, size_t n);
@@ -115,5 +122,22 @@ char *zn_strdup(Zone *z, const char *s) {
return d;
}
+void zn_save(Zone *z, ZoneState *m) {
+ m->zf = z->here;
+ m->length = z->here ? z->tail->length : 0;
+}
+
+void zn_load(Zone *z, ZoneState *m) {
+ if (m->zf) {
+ while (z->here != m->zf) {
+ z->here->length = 0;
+ z->here = z->here->prev;
+ }
+ m->zf->length = m->length;
+ } else {
+ zn_clear(z);
+ }
+}
+
#endif
#endif