dirvec: add dirvec_for_each iterator
This will make it easier to introduce locking
This commit is contained in:
parent
1d385190a0
commit
f2525e3efb
16
src/dirvec.c
16
src/dirvec.c
|
@ -78,3 +78,19 @@ void dirvec_destroy(struct dirvec *dv)
|
|||
}
|
||||
dv->nr = 0;
|
||||
}
|
||||
|
||||
int dirvec_for_each(const struct dirvec *dv,
|
||||
int (*fn)(struct directory *, void *), void *arg)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < dv->nr; ++i) {
|
||||
struct directory *dir = dv->base[i];
|
||||
|
||||
assert(dir);
|
||||
if (fn(dir, arg) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,4 +24,7 @@ dirvec_clear(struct dirvec *dv)
|
|||
|
||||
void dirvec_destroy(struct dirvec *dv);
|
||||
|
||||
int dirvec_for_each(const struct dirvec *dv,
|
||||
int (*fn)(struct directory *, void *), void *arg);
|
||||
|
||||
#endif /* DIRVEC_H */
|
||||
|
|
Loading…
Reference in New Issue