Now we don't need to worry about freeing them. In particular, `popall'
now becomes trivial.
/* --- @splitpath@ --- *
*
/* --- @splitpath@ --- *
*
- * Arguments: @const char *path@ = path string to break apart
+ * Arguments: @struct state *state@ = pointer to state
+ * @const char *path@ = path string to break apart
* @struct elt *tail@ = tail block to attach to end of list
*
* Returns: Pointer to the new list head.
* @struct elt *tail@ = tail block to attach to end of list
*
* Returns: Pointer to the new list head.
* be pushed onto the directory stack as required.
*/
* be pushed onto the directory stack as required.
*/
-static struct elt *splitpath(const char *path, struct elt *tail)
+static struct elt *splitpath(struct state *state,
+ const char *path, struct elt *tail)
{
struct elt *head, **ee = &head, *e;
size_t n;
{
struct elt *head, **ee = &head, *e;
size_t n;
*/
n = strcspn(path, "/");
*/
n = strcspn(path, "/");
- e = xmalloc(sizeof(struct elt) + n + 1);
+ e = pool_alloc(state->p, offsetof(struct elt, e_name) + n + 1);
memcpy(e->e_name, path, n);
e->e_name[n] = 0;
e->e_flags = 0;
memcpy(e->e_name, path, n);
e->e_name[n] = 0;
e->e_flags = 0;
e = sp->e_link;
state->path.len = sp->e_offset;
DPUTZ(&state->path);
e = sp->e_link;
state->path.len = sp->e_offset;
DPUTZ(&state->path);
- xfree(state->sp); state->sp = e;
*/
static void popall(struct state *state)
*/
static void popall(struct state *state)
- { while (state->sp->e_link) pop(state); }
+ { state->sp = (/*unconst*/ struct elt *)&rootnode; state->path.len = 0; }
/* --- Get the initial list of things to process --- */
/* --- Get the initial list of things to process --- */
+ ee = splitpath(state, p, 0);
- ee = splitpath(cwd, ee);
+ ee = splitpath(state, cwd, ee);
/* --- While there are list items which still need doing --- */
/* --- While there are list items which still need doing --- */
/* --- Strip off simple `.' elements --- */
if (strcmp(ee->e_name, ".") == 0) {
/* --- Strip off simple `.' elements --- */
if (strcmp(ee->e_name, ".") == 0) {
else if (strcmp(ee->e_name, "..") == 0) {
pop(state);
else if (strcmp(ee->e_name, "..") == 0) {
pop(state);
popall(state);
else
pop(state);
popall(state);
else
pop(state);
- ee = splitpath(buf.buf, ee);
+ ee = splitpath(state, buf.buf, ee);
report(cp, CP_ERROR, 0, 0, "junk left over after reaching leaf");
while (ee) {
e = ee->e_link;
report(cp, CP_ERROR, 0, 0, "junk left over after reaching leaf");
while (ee) {
e = ee->e_link;
dstr_destroy(&state->path);
dstr_destroy(&buf);
pool_destroy(state->p);
dstr_destroy(&state->path);
dstr_destroy(&buf);
pool_destroy(state->p);