-
-struct span {
- struct span *next;
- unsigned long ofs;
- unsigned long end;
-};
-
-static void touch_range(struct span **span,
- unsigned long ofs, unsigned long end)
-{
- struct span *e = *span;
- struct span *p = NULL;
-
- while (e && e->ofs <= ofs) {
- again:
- if (ofs < e->end) {
- while (e->end < end) {
- if (e->next) {
- e->end = e->next->ofs;
- e = e->next;
- }
- else {
- e->end = end;
- return;
- }
- }
- return;
- }
- p = e;
- e = e->next;
- }
- if (e && e->ofs <= end) {
- e->ofs = ofs;
- goto again;
- }
- else {
- e = xmalloc(sizeof(*e));
- e->ofs = ofs;
- e->end = end;
- if (p) {
- e->next = p->next;
- p->next = e;
- }
- else {
- e->next = *span;
- *span = e;
- }
- }
-}
-
-static unsigned long count_range(struct span *s)
-{
- struct span *t;
- unsigned long sz = 0;
- while (s) {
- t = s;
- sz += s->end - s->ofs;
- s = s->next;
- free(t);
- }
- return sz;
-}