15
typedef stack_t Stack;
19
Stack* s = (Stack*) malloc(sizeof(Stack));
22
fprintf(stderr, "new_stack: Memory allocation failure! (1)\n");
25
s->items = (const char**) malloc(16 * sizeof(const char*));
28
fprintf(stderr, "new_stack: Memory allocation failure! (2)\n");
36
void stack_push(Stack* s,const char* itm)
38
if (s->top == s->capacity)
40
int c = s->capacity * 2;
41
const char** itms = (const char**) malloc(c * sizeof(const char*));
44
fprintf(stderr, "stack_push: Memory allocation failure! (1)\n");
47
memcpy(itms, s->items, s->capacity * sizeof(const char*));
52
s->items[s->top++] = itm;
55
const char* stack_pop(Stack* s)
59
fprintf(stderr, "stack_pop: underflow!\n");
62
return s->items[--(s->top)];
65
void old_stack(Stack* s)
74
* Normalize the unix pathname in src eliminating .. sequences
75
* to yield an absolute path. Returns 0 on success, and -1 on
78
int norm(char* dest, int len, const char* src)
85
if (!*s || (*d++ = *s++) != '/')
95
while (*s && (*d++ = *s++) != '/') ;
102
fprintf(stderr,"%s\n",x);
104
if (strncmp(t, "..", l) == 0)
106
fprintf(stderr,"backtracking...\n");
108
while (d > dest && *--d != '/')
114
/* underflow: too many .. sequences */
121
fprintf(stderr, "returning: '%s'\n", dest);