Branch Coverage

src/b_find.c
Criterion Covered Total %
branch 64 136 47.0


line true false branch
18 0 6588 int (*statfn)(const char *, struct stat *) = (flags & B_FIND_FOLLOW_SYMLINKS)? stat: lstat;
31 0 88 if ((dir = malloc(sizeof(*dir))) == NULL) {
35 0 88 if ((dir->dp = opendir(path->str)) == NULL) {
39 0 88 if ((dir->path = b_string_dup(path)) == NULL) {
56 88 0 if (item->dp) {
62 0 88 if (item == NULL) return;
85 88 699 if ((entry = readdir(dir->dp)) == NULL) {
89 0 699 if ((item = malloc(sizeof(*item))) == NULL) {
93 0 699 if ((item->path = b_string_dup(dir->path)) == NULL) {
97 0 699 if ((item->name = b_string_new(entry->d_name)) == NULL) {
104 699 0 if (strcmp(item->path->str, "/") != 0) {
105 0 699 if (b_string_append_str(item->path, "/") == NULL) {
110 0 699 if (b_string_append_str(item->path, entry->d_name) == NULL) {
131 0 699 if (item == NULL) return;
149 42 439 if (strcmp(path->str, member_name->str) != 0) {
150 0 42 if ((new_member_name = b_string_dup(member_name)) == NULL) {
154 0 42 if (b_string_append_str(new_member_name, current->str + b_string_len(path)) == NULL) {
183 0 6588 if (flags & B_FIND_FOLLOW_SYMLINKS) {
187 0 6588 if ((clean_path = b_path_clean(path)) == NULL) {
191 0 6588 if ((clean_member_name = b_path_clean(member_name)) == NULL) {
195 0 6588 if ((dirs = b_stack_new(0)) == NULL) {
201 0 6588 if (b_stat(clean_path, &st, flags) < 0) {
211 6556 32 if ((st.st_mode & S_IFMT) == S_IFREG) {
212 0 6556 if ((fd = open(clean_path->str, oflags)) < 0) {
215 0 6556 if (fcntl(fd, F_SETFL, oflags & ~O_NONBLOCK)) // previously clear_nonblock, however we know oflags so we can do it outselves
221 6556 32 if (fd > 0) {
226 0 6588 if (res == 0) {
228 8 6580 } else if (res < 0) {
232 6548 32 if ((st.st_mode & S_IFMT) != S_IFDIR) {
236 0 32 if ((dir = b_dir_open(clean_path)) == NULL) {
237 0 0 if (err) {
244 0 32 if (b_stack_push(dirs, dir) == NULL) {
256 32 787 if (cwd == NULL) {
260 88 699 if ((item = b_dir_read(cwd, flags)) == NULL) {
263 88 0 if (oldcwd) {
270 611 88 if (strcmp(item->name->str, ".") == 0 || strcmp(item->name->str, "..") == 0) {
523 88 if (strcmp(item->name->str, ".") == 0 || strcmp(item->name->str, "..") == 0) {
279 119 404 if (builder->match != NULL && lafe_excluded(builder->match, (const char *)item->path->str)) {
42 77 if (builder->match != NULL && lafe_excluded(builder->match, (const char *)item->path->str)) {
283 0 481 if ((item_fd = open(item->path->str, oflags)) < 0) {
297 0 0 if ((oflags & O_NOFOLLOW) && (errno == ELOOP || errno == EMLINK || errno == EFTYPE)) {
0 0 if ((oflags & O_NOFOLLOW) && (errno == ELOOP || errno == EMLINK || errno == EFTYPE)) {
0 0 if ((oflags & O_NOFOLLOW) && (errno == ELOOP || errno == EMLINK || errno == EFTYPE)) {
0 0 if ((oflags & O_NOFOLLOW) && (errno == ELOOP || errno == EMLINK || errno == EFTYPE)) {
298 0 0 if (lstat(item->path->str, &item_st) < 0) {
299 0 0 if (err) {
306 0 0 if( flags & B_FIND_IGNORE_SOCKETS ) {
307 0 0 if (stat(item->path->str, &item_st) < 0) {
308 0 0 if (err) {
313 0 0 if( err && (item_st.st_mode & S_IFMT) != S_IFSOCK ) {
0 0 if( err && (item_st.st_mode & S_IFMT) != S_IFSOCK ) {
319 0 0 if (err) {
327 0 481 if (fcntl(fd, F_SETFL, oflags & ~O_NONBLOCK)) // previously clear_nonblock, however we know oflags so we can do it outselves
329 0 481 if (fstat(item_fd, &item_st) < 0) {
330 0 0 if (err) {
344 439 42 res = callback(builder, item->path, new_member_name? new_member_name: item->path, &item_st, item_fd);
348 0 481 if (res == 0) {
350 0 481 } else if (res < 0) {
351 0 0 if (err && !b_error_fatal(err)) {
0 0 if (err && !b_error_fatal(err)) {
358 56 425 if ((item_st.st_mode & S_IFMT) == S_IFDIR) {
361 0 56 if ((newdir = b_dir_open(item->path)) == NULL) {
362 0 0 if (err) {
366 0 0 if (errno == EACCES) {
373 0 56 if (b_stack_push(dirs, newdir) == NULL) {
381 481 218 if (item_fd > 0) {
391 0 0 if (item_fd > 0) {
412 0 8 if (fd > 0) {