Branch Coverage

file.c
Criterion Covered Total %
branch 739 1332 55.4


line true false branch
141 335 51 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
148 187 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
146 32 206 if (stat(path, st) < 0) {
153 206 0 if (len < STAT_CACHE_PATH_MAX) {
177 1 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
189 1 8 if (cached_stat(path, &st) < 0) return 0;
191 8 0 if (g_stat_cache.uid == 0) return 1; /* root can read anything */
193 0 0 if (st.st_uid == g_stat_cache.uid) {
195 0 0 } else if (st.st_gid == g_stat_cache.gid) {
210 1 8 if (cached_stat(path, &st) < 0) return 0;
212 8 0 if (g_stat_cache.uid == 0) return 1; /* root can write anything */
214 0 0 if (st.st_uid == g_stat_cache.uid) {
216 0 0 } else if (st.st_gid == g_stat_cache.gid) {
239 0 8 if (cached_stat(path, &st) < 0) return 0;
241 8 0 if (g_stat_cache.uid == 0) return 1; /* root can execute anything */
243 0 0 if (st.st_uid == g_stat_cache.uid) {
245 0 0 } else if (st.st_gid == g_stat_cache.gid) {
340 73 2 if (g_file_read_hook || g_file_hooks[FILE_HOOK_PHASE_READ]) {
7 66 if (g_file_read_hook || g_file_hooks[FILE_HOOK_PHASE_READ]) {
353 0 66 if (fd < 0) {
359 66 0 if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode)) {
0 66 if (fstat(fd, &st) < 0 || !S_ISREG(st.st_mode)) {
367 1 65 if (st.st_size == 0) {
385 0 65 if (st.st_size >= MMAP_SLURP_THRESHOLD) {
387 0 0 if (map != MAP_FAILED) {
406 65 0 if (n == st.st_size) {
417 0 0 if (n < 0) {
418 0 0 if (errno == EINTR) {
430 0 0 while (total < st.st_size) {
432 0 0 if (n < 0) {
433 0 0 if (errno == EINTR) continue;
440 0 0 if (n == 0) break;
459 71 0 PUSHs(file_spew_internal(aTHX_ path, data) ? &PL_sv_yes : &PL_sv_no);
469 140 7 PUSHs(file_exists_internal(path) ? &PL_sv_yes : &PL_sv_no);
489 17 12 PUSHs(file_is_file_internal(path) ? &PL_sv_yes : &PL_sv_no);
499 10 14 PUSHs(file_is_dir_internal(path) ? &PL_sv_yes : &PL_sv_no);
512 0 6 if (content == &PL_sv_undef) {
529 1 1 PUSHs(file_unlink_internal(path) ? &PL_sv_yes : &PL_sv_no);
539 1 0 if (SvOK(path_sv)) {
558 4 0 PUSHs(file_mkdir_internal(path, 0755) ? &PL_sv_yes : &PL_sv_no);
568 1 0 PUSHs(file_rmdir_internal(path) ? &PL_sv_yes : &PL_sv_no);
578 1 0 PUSHs(file_touch_internal(path) ? &PL_sv_yes : &PL_sv_no);
658 2 4 PUSHs(file_is_link_internal(path) ? &PL_sv_yes : &PL_sv_no);
668 7 0 PUSHs(file_is_readable_internal(path) ? &PL_sv_yes : &PL_sv_no);
678 6 0 PUSHs(file_is_writable_internal(path) ? &PL_sv_yes : &PL_sv_no);
688 8 0 PUSHs(file_is_executable_internal(path) ? &PL_sv_yes : &PL_sv_no);
722 1 0 PUSHs(file_copy_internal(aTHX_ src, dst) ? &PL_sv_yes : &PL_sv_no);
734 0 0 PUSHs(file_move_internal(aTHX_ src, dst) ? &PL_sv_yes : &PL_sv_no);
746 0 0 PUSHs(file_chmod_internal(path, mode) ? &PL_sv_yes : &PL_sv_no);
757 2 0 PUSHs(file_append_internal(aTHX_ path, data) ? &PL_sv_yes : &PL_sv_no);
768 0 0 PUSHs(file_atomic_spew_internal(aTHX_ path, data) ? &PL_sv_yes : &PL_sv_no);
787 170 0 if (!OpHAS_SIBLING(pushop)) {
792 170 0 argop = OpSIBLING(pushop);
793 0 170 if (!argop) return entersubop;
795 169 1 cvop = OpSIBLING(argop);
796 1 169 if (!cvop) return entersubop;
799 169 0 if (OpSIBLING(argop) != cvop) return entersubop;
0 169 if (OpSIBLING(argop) != cvop) return entersubop;
828 46 0 if (!OpHAS_SIBLING(pushop)) {
833 46 0 pathop = OpSIBLING(pushop);
834 0 46 if (!pathop) return entersubop;
836 46 0 dataop = OpSIBLING(pathop);
837 0 46 if (!dataop) return entersubop;
839 46 0 cvop = OpSIBLING(dataop);
840 0 46 if (!cvop) return entersubop;
843 46 0 if (OpSIBLING(dataop) != cvop) return entersubop;
0 46 if (OpSIBLING(dataop) != cvop) return entersubop;
951 0 18 if (file_initialized) return;
954 0 18 Newxz(g_mmaps, g_mmaps_size, MmapEntry);
956 0 18 Newxz(g_free_mmaps, g_free_mmaps_size, IV);
959 0 18 Newxz(g_iters, g_iters_size, LineIterEntry);
961 0 18 Newxz(g_free_iters, g_free_iters_size, IV);
993 2 42 if (fd < 0 && errno == EPERM) {
0 2 if (fd < 0 && errno == EPERM) {
997 2 42 if (fd < 0) {
1001 0 42 if (fstat(fd, &st) < 0) {
1010 42 0 if (S_ISREG(st.st_mode) && st.st_size > 0) {
37 5 if (S_ISREG(st.st_mode) && st.st_size > 0) {
1013 0 37 if (st.st_size >= MMAP_SLURP_THRESHOLD) {
1015 0 0 if (map != MAP_FAILED) {
1040 37 37 while (total < st.st_size) {
1042 0 37 if (n < 0) {
1043 0 0 if (errno == EINTR) continue;
1048 0 37 if (n == 0) break;
1062 0 5 if (total >= (ssize_t)capacity - 1) {
1064 0 0 SvGROW(result, capacity);
0 0 SvGROW(result, capacity);
1069 0 5 if (n < 0) {
1070 0 0 if (errno == EINTR) continue;
1075 5 0 if (n == 0) break;
1087 40 2 if (g_file_read_hook || g_file_hooks[FILE_HOOK_PHASE_READ]) {
7 33 if (g_file_read_hook || g_file_hooks[FILE_HOOK_PHASE_READ]) {
1089 0 9 if (!hooked) {
1093 9 0 if (hooked != result) {
1125 0 3 if (fd < 0 && errno == EPERM) {
0 0 if (fd < 0 && errno == EPERM) {
1129 0 3 if (fd < 0) {
1133 0 3 if (fstat(fd, &st) < 0) {
1141 3 0 if (S_ISREG(st.st_mode) && st.st_size > 0) {
3 0 if (S_ISREG(st.st_mode) && st.st_size > 0) {
1144 0 3 if (st.st_size >= MMAP_SLURP_THRESHOLD) {
1146 0 0 if (map != MAP_FAILED) {
1168 3 3 while (total < st.st_size) {
1170 0 3 if (n < 0) {
1171 0 0 if (errno == EINTR) continue;
1176 0 3 if (n == 0) break;
1189 0 0 if (total >= (ssize_t)capacity - 1) {
1191 0 0 SvGROW(result, capacity);
0 0 SvGROW(result, capacity);
1196 0 0 if (n < 0) {
1197 0 0 if (errno == EINTR) continue;
1202 0 0 if (n == 0) break;
1236 154 2 if (UNLIKELY(g_file_write_hook || g_file_hooks[FILE_HOOK_PHASE_WRITE])) {
3 151 if (UNLIKELY(g_file_write_hook || g_file_hooks[FILE_HOOK_PHASE_WRITE])) {
1238 0 5 if (!hooked) {
1241 5 0 if (hooked != data) {
1250 0 156 if (UNLIKELY(fd < 0)) {
1251 0 0 if (free_write_data) SvREFCNT_dec(write_data);
1257 4 152 if (len >= 65536) {
1264 156 0 if (LIKELY(n == (ssize_t)len)) {
1266 5 151 if (free_write_data) SvREFCNT_dec(write_data);
1268 62 94 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2 60 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1275 0 0 if (n < 0) {
1276 0 0 if (errno != EINTR) {
1278 0 0 if (free_write_data) SvREFCNT_dec(write_data);
1287 0 0 while ((size_t)written < len) {
1289 0 0 if (n < 0) {
1290 0 0 if (errno == EINTR) continue;
1292 0 0 if (free_write_data) SvREFCNT_dec(write_data);
1300 0 0 if (free_write_data) SvREFCNT_dec(write_data);
1302 0 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
0 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1326 0 4 if (UNLIKELY(fd < 0)) {
1332 4 0 if (LIKELY(n == (ssize_t)len)) {
1335 4 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1 3 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1342 0 0 if (n < 0) {
1343 0 0 if (errno != EINTR) {
1353 0 0 while ((size_t)written < len) {
1355 0 0 if (n < 0) {
1356 0 0 if (errno == EINTR) continue;
1366 0 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
0 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1377 0 4 if (needed >= g_mmaps_size) {
1378 0 0 IV new_size = g_mmaps_size ? g_mmaps_size * 2 : 16;
1380 0 0 while (new_size <= needed) new_size *= 2;
1381 0 0 Renew(g_mmaps, new_size, MmapEntry);
1382 0 0 for (i = g_mmaps_size; i < new_size; i++) {
1400 10 4 if (g_free_mmaps_count > 0) {
1413 14 0 if (idx < 0 || idx >= g_mmaps_count) return;
0 14 if (idx < 0 || idx >= g_mmaps_count) return;
1429 14 0 if (entry->addr && entry->addr != MAP_FAILED) {
14 0 if (entry->addr && entry->addr != MAP_FAILED) {
1432 14 0 if (entry->fd >= 0) {
1441 0 14 if (g_free_mmaps_count >= g_free_mmaps_size) {
1443 0 0 Renew(g_free_mmaps, g_free_mmaps_size, IV);
1503 1 15 int flags = writable ? O_RDWR : O_RDONLY;
1504 1 15 int prot = writable ? (PROT_READ | PROT_WRITE) : PROT_READ;
1507 1 15 if (fd < 0) {
1511 0 15 if (fstat(fd, &st) < 0) {
1516 1 14 if (st.st_size == 0) {
1525 0 14 if (addr == MAP_FAILED) {
1544 14 0 if (idx < 0 || idx >= g_mmaps_count) {
0 14 if (idx < 0 || idx >= g_mmaps_count) {
1554 14 0 if (!entry->addr || entry->addr == MAP_FAILED) {
0 14 if (!entry->addr || entry->addr == MAP_FAILED) {
1561 14 0 SvUPGRADE(sv, SVt_PV);
1573 14 2 if (idx < 0 || idx >= g_mmaps_count) return;
0 14 if (idx < 0 || idx >= g_mmaps_count) return;
1577 14 0 if (entry->refcount <= 0) {
1586 2 0 if (idx < 0 || idx >= g_mmaps_count) return;
0 2 if (idx < 0 || idx >= g_mmaps_count) return;
1594 2 0 if (entry->addr && entry->addr != MAP_FAILED) {
2 0 if (entry->addr && entry->addr != MAP_FAILED) {
1605 0 7 if (needed >= g_iters_size) {
1606 0 0 IV new_size = g_iters_size ? g_iters_size * 2 : 16;
1608 0 0 while (new_size <= needed) new_size *= 2;
1609 0 0 Renew(g_iters, new_size, LineIterEntry);
1610 0 0 for (i = g_iters_size; i < new_size; i++) {
1627 51 7 if (g_free_iters_count > 0) {
1640 57 0 if (idx < 0 || idx >= g_iters_count) return;
0 57 if (idx < 0 || idx >= g_iters_count) return;
1643 57 0 if (entry->fd >= 0) {
1646 57 0 if (entry->buffer) {
1649 57 0 if (entry->path) {
1662 0 57 if (g_free_iters_count >= g_free_iters_size) {
1664 0 0 Renew(g_free_iters, g_free_iters_size, IV);
1681 4 58 if (fd < 0) {
1711 1291 0 if (idx < 0 || idx >= g_iters_count) {
0 1291 if (idx < 0 || idx >= g_iters_count) {
1716 0 1291 if (entry->fd < 0) {
1722 1268 84 if (entry->buf_pos < entry->buf_len) {
1726 1256 12 if (newline) {
1735 35 61 if (entry->eof) {
1737 6 29 if (entry->buf_pos < entry->buf_len) {
1747 26 35 if (entry->buf_pos > 0) {
1749 6 20 if (remaining > 0) {
1757 0 61 if (entry->buf_len >= entry->buf_size - 1) {
1765 0 61 if (n < 0) {
1766 0 0 if (errno == EINTR) continue;
1769 29 32 if (n == 0) {
1781 0 0 if (idx < 0 || idx >= g_iters_count) {
0 0 if (idx < 0 || idx >= g_iters_count) {
1786 0 0 return entry->eof && entry->buf_pos >= entry->buf_len;
0 0 return entry->eof && entry->buf_pos >= entry->buf_len;
1791 57 1 if (idx < 0 || idx >= g_iters_count) return;
0 57 if (idx < 0 || idx >= g_iters_count) return;
1795 57 0 if (entry->refcount <= 0) {
1807 2 63 if (cached_stat(path, &st) < 0) {
1822 2 31 if (cached_stat(path, &st) < 0) return 0;
1829 7 31 if (cached_stat(path, &st) < 0) return 0;
1846 1 30 if (cached_stat(path, &st) < 0) {
1855 1 7 if (cached_stat(path, &st) < 0) {
1864 1 7 if (cached_stat(path, &st) < 0) {
1873 1 4 if (cached_stat(path, &st) < 0) {
1884 1 3 if (cached_stat(path, &st) < 0) {
1894 2 1 hv_store(result, "is_file", 7, S_ISREG(st.st_mode) ? &PL_sv_yes : &PL_sv_no, 0);
1895 1 2 hv_store(result, "is_dir", 6, S_ISDIR(st.st_mode) ? &PL_sv_yes : &PL_sv_no, 0);
1914 1 9 if (lstat(path, &st) < 0) return 0;
1949 2 4 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1974 1 3 if (fd_src < 0) return 0;
1976 3 0 if (fstat(fd_src, &st) < 0 || !S_ISREG(st.st_mode)) {
0 3 if (fstat(fd_src, &st) < 0 || !S_ISREG(st.st_mode)) {
1982 0 3 if (fd_dst < 0) {
1988 2 3 while (offset < st.st_size) {
1990 0 2 if (sent < 0) {
1991 0 0 if (errno == EINTR) continue;
1992 0 0 if (errno == EINVAL || errno == ENOSYS) {
0 0 if (errno == EINVAL || errno == ENOSYS) {
2004 0 0 if (n_read < 0) {
2005 0 0 if (errno == EINTR) continue;
2008 0 0 if (n_read == 0) { result = 1; break; }
2011 0 0 while (written < n_read) {
2013 0 0 if (n_written < 0) {
2014 0 0 if (errno == EINTR) continue;
2024 0 0 if (result && g_stat_cache.valid && strcmp(dst, g_stat_cache.path) == 0) {
0 0 if (result && g_stat_cache.valid && strcmp(dst, g_stat_cache.path) == 0) {
0 0 if (result && g_stat_cache.valid && strcmp(dst, g_stat_cache.path) == 0) {
2033 0 2 if (sent == 0) break;
2039 1 2 if (g_stat_cache.valid && strcmp(dst, g_stat_cache.path) == 0) {
0 1 if (g_stat_cache.valid && strcmp(dst, g_stat_cache.path) == 0) {
2110 2 1 if (rename(src, dst) == 0) {
2114 0 1 else if (errno == EXDEV) {
2115 0 0 if (file_copy_internal(aTHX_ src, dst)) {
2125 1 1 if (g_stat_cache.valid) {
2126 1 0 if (strcmp(src, g_stat_cache.path) == 0 || strcmp(dst, g_stat_cache.path) == 0) {
0 1 if (strcmp(src, g_stat_cache.path) == 0 || strcmp(dst, g_stat_cache.path) == 0) {
2156 1 2 if (utime(path, NULL) == 0) {
2161 0 2 if (fd < 0) {
2169 2 1 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1 1 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2184 1 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
0 1 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2200 6 12 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
1 5 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2215 2 7 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2 0 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2259 2 5 if (!dir) return result;
2261 27 5 while ((entry = readdir(dir)) != NULL) {
2263 22 5 if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
17 5 if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
2282 2 81 if (len == 0) return newSVpvs("");
2285 85 3 while (len > 0 && (path[len-1] == '/' || path[len-1] == '\\')) {
7 78 while (len > 0 && (path[len-1] == '/' || path[len-1] == '\\')) {
0 78 while (len > 0 && (path[len-1] == '/' || path[len-1] == '\\')) {
2288 3 78 if (len == 0) return newSVpvs("");
2292 732 3 while (p > path && *p != '/' && *p != '\\') {
657 75 while (p > path && *p != '/' && *p != '\\') {
657 0 while (p > path && *p != '/' && *p != '\\') {
2295 3 75 if (*p == '/' || *p == '\\') p++;
0 3 if (*p == '/' || *p == '\\') p++;
2304 1 19 if (len == 0) return newSVpvs(".");
2308 19 2 while (end > path && (*end == '/' || *end == '\\')) {
2 17 while (end > path && (*end == '/' || *end == '\\')) {
0 17 while (end > path && (*end == '/' || *end == '\\')) {
2313 131 6 while (end > path && *end != '/' && *end != '\\') {
118 13 while (end > path && *end != '/' && *end != '\\') {
118 0 while (end > path && *end != '/' && *end != '\\') {
2317 6 13 if (end == path) {
2318 2 4 if (*end == '/' || *end == '\\') {
0 2 if (*end == '/' || *end == '\\') {
2325 14 0 while (end > path && (*(end-1) == '/' || *(end-1) == '\\')) {
1 13 while (end > path && (*(end-1) == '/' || *(end-1) == '\\')) {
0 13 while (end > path && (*(end-1) == '/' || *(end-1) == '\\')) {
2337 1 48 if (len == 0) return newSVpvs("");
2341 440 12 while (basename > path && *basename != '/' && *basename != '\\') {
404 36 while (basename > path && *basename != '/' && *basename != '\\') {
404 0 while (basename > path && *basename != '/' && *basename != '\\') {
2344 12 36 if (*basename == '/' || *basename == '\\') basename++;
0 12 if (*basename == '/' || *basename == '\\') basename++;
2348 44 4 if (!dot || dot == basename) return newSVpvs("");
2 42 if (!dot || dot == basename) return newSVpvs("");
2361 0 12 if (len == 0) return newSVpvs("");
2364 28 12 for (i = 0; i < len; i++) {
2366 28 0 if (sv && SvPOK(*sv)) {
28 0 if (sv && SvPOK(*sv)) {
2377 28 12 for (i = 0; i < len; i++) {
2379 28 0 if (sv && SvPOK(*sv)) {
28 0 if (sv && SvPOK(*sv)) {
2383 1 27 if (part_len == 0) continue;
2386 29 0 while (part_len > 0 && (*part == '/' || *part == '\\')) {
9 20 while (part_len > 0 && (*part == '/' || *part == '\\')) {
0 20 while (part_len > 0 && (*part == '/' || *part == '\\')) {
2387 9 0 if (!need_sep && p == buf) break; /* Keep root slash */
7 2 if (!need_sep && p == buf) break; /* Keep root slash */
2392 12 15 if (need_sep && part_len > 0) {
12 0 if (need_sep && part_len > 0) {
2400 27 0 if (part_len > 0) {
2405 24 3 need_sep = (*(p-1) != '/' && *(p-1) != '\\');
24 0 need_sep = (*(p-1) != '/' && *(p-1) != '\\');
2425 1 5 if (n <= 0) return result;
2428 1 4 if (idx < 0) return result;
2430 20 2 while (count < n && (line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
18 2 while (count < n && (line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
2446 1 5 if (n <= 0) return result;
2449 1 4 if (idx < 0) return result;
2455 43 4 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
2456 25 18 if (av_len(buffer) + 1 >= n) {
2467 18 4 for (i = 0; i < buf_len; i++) {
2469 18 0 if (sv) {
2503 0 14 if (fd < 0) {
2507 13 14 while ((size_t)written < len) {
2509 0 13 if (n < 0) {
2510 0 0 if (errno == EINTR) continue;
2529 0 14 if (rename(temp_path, path) != 0) {
2535 10 4 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
0 10 if (g_stat_cache.valid && strcmp(path, g_stat_cache.path) == 0) {
2554 14 2 while (start < end) {
2556 10 4 if (p) {
2560 4 0 if (start < end) {
2578 0 29 if (items != 1) croak("Usage: file::slurp(path)");
2589 0 2 if (items != 1) croak("Usage: file::slurp_raw(path)");
2600 0 85 if (items != 2) croak("Usage: file::spew(path, data)");
2603 85 0 if (file_spew_internal(aTHX_ path, ST(1))) {
2615 0 2 if (items != 2) croak("Usage: file::append(path, data)");
2618 2 0 if (file_append_internal(aTHX_ path, ST(1))) {
2631 0 11 if (items != 1) croak("Usage: file::size(path)");
2644 0 4 if (items != 1) croak("Usage: file::mtime(path)");
2656 0 21 if (items != 1) croak("Usage: file::exists(path)");
2659 14 7 ST(0) = file_exists_internal(path) ? &PL_sv_yes : &PL_sv_no;
2667 0 4 if (items != 1) croak("Usage: file::is_file(path)");
2670 3 1 ST(0) = file_is_file_internal(path) ? &PL_sv_yes : &PL_sv_no;
2678 0 7 if (items != 1) croak("Usage: file::is_dir(path)");
2681 4 3 ST(0) = file_is_dir_internal(path) ? &PL_sv_yes : &PL_sv_no;
2689 0 2 if (items != 1) croak("Usage: file::is_readable(path)");
2692 1 1 ST(0) = file_is_readable_internal(path) ? &PL_sv_yes : &PL_sv_no;
2700 0 3 if (items != 1) croak("Usage: file::is_writable(path)");
2703 2 1 ST(0) = file_is_writable_internal(path) ? &PL_sv_yes : &PL_sv_no;
2723 0 7 if (items != 1) croak("Usage: file::lines(path)");
2728 1 6 if (UNLIKELY(fd < 0)) {
2734 6 0 if (UNLIKELY(fstat(fd, &st) < 0 || st.st_size == 0)) {
1 5 if (UNLIKELY(fstat(fd, &st) < 0 || st.st_size == 0)) {
2745 5 5 while ((size_t)total_read < file_size) {
2747 0 5 if (UNLIKELY(n < 0)) {
2748 0 0 if (errno == EINTR) continue;
2751 0 5 if (n == 0) break;
2756 0 5 if (UNLIKELY(total_read == 0)) {
2771 15 0 while (p < end) {
2773 10 5 if (LIKELY(p != NULL)) {
2779 5 0 if (line_start < end) {
2799 16 0 if (items < 1 || items > 2) croak("Usage: file::mmap_open(path, [writable])");
0 16 if (items < 1 || items > 2) croak("Usage: file::mmap_open(path, [writable])");
2802 1 15 writable = (items > 1 && SvTRUE(ST(1))) ? 1 : 0;
1 0 writable = (items > 1 && SvTRUE(ST(1))) ? 1 : 0;
2805 2 14 if (idx < 0) {
2824 0 14 if (items != 1) croak("Usage: $mmap->data");
2826 14 0 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
0 14 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
2832 14 0 idx = idx_sv ? SvIV(*idx_sv) : -1;
2844 0 2 if (items != 1) croak("Usage: $mmap->sync");
2846 2 0 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
0 2 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
2852 2 0 idx = idx_sv ? SvIV(*idx_sv) : -1;
2864 0 16 if (items != 1) croak("Usage: $mmap->close");
2866 16 0 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
0 16 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
2872 16 0 idx = idx_sv ? SvIV(*idx_sv) : -1;
2887 0 14 if (PL_dirty) XSRETURN_EMPTY;
2889 14 0 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
0 14 if (!SvROK(ST(0)) || SvTYPE(SvRV(ST(0))) != SVt_PVHV) {
2895 14 0 idx = idx_sv ? SvIV(*idx_sv) : -1;
2897 0 14 if (idx >= 0) {
2909 0 18 if (items != 1) croak("Usage: file::lines_iter(path)");
2914 1 17 if (idx < 0) {
2936 0 153 if (items != 1) croak("Usage: $iter->next");
2939 0 153 if (UNLIKELY(!SvROK(rv))) {
2946 153 0 if (UNLIKELY(idx < 0 || idx >= g_iters_count)) {
0 153 if (UNLIKELY(idx < 0 || idx >= g_iters_count)) {
2952 0 153 if (UNLIKELY(entry->fd < 0)) {
2960 163 22 if (entry->buf_pos < entry->buf_len) {
2964 139 24 if (newline) {
2974 14 32 if (entry->eof) {
2976 11 3 if (entry->buf_pos < entry->buf_len) {
2988 12 20 if (entry->buf_pos > 0) {
2990 10 2 if (remaining > 0) {
2998 1 31 if (entry->buf_len >= entry->buf_size - 1) {
3006 0 32 if (n < 0) {
3007 0 0 if (errno == EINTR) continue;
3011 14 18 if (n == 0) {
3025 0 123 if (items != 1) croak("Usage: $iter->eof");
3028 0 123 if (UNLIKELY(!SvROK(rv))) {
3035 123 0 if (UNLIKELY(idx < 0 || idx >= g_iters_count)) {
0 123 if (UNLIKELY(idx < 0 || idx >= g_iters_count)) {
3041 9 114 ST(0) = (entry->eof && entry->buf_pos >= entry->buf_len) ? &PL_sv_yes : &PL_sv_no;
9 0 ST(0) = (entry->eof && entry->buf_pos >= entry->buf_len) ? &PL_sv_yes : &PL_sv_no;
3050 0 18 if (items != 1) croak("Usage: $iter->close");
3053 0 18 if (UNLIKELY(!SvROK(rv))) {
3072 0 17 if (PL_dirty) XSRETURN_EMPTY;
3075 0 17 if (UNLIKELY(!SvROK(rv))) {
3081 0 17 if (idx >= 0) {
3109 50 10 for (i = 0; i < len; i++) {
3110 35 15 if (s[i] != ' ' && s[i] != '\t' && s[i] != '\r' && s[i] != '\n') {
35 0 if (s[i] != ' ' && s[i] != '\t' && s[i] != '\r' && s[i] != '\n') {
35 0 if (s[i] != ' ' && s[i] != '\t' && s[i] != '\r' && s[i] != '\n') {
35 0 if (s[i] != ' ' && s[i] != '\t' && s[i] != '\r' && s[i] != '\n') {
3133 27 6 while (len > 0 && (*s == ' ' || *s == '\t')) {
9 18 while (len > 0 && (*s == ' ' || *s == '\t')) {
0 18 while (len > 0 && (*s == ' ' || *s == '\t')) {
3137 18 6 return len > 0 && *s == '#';
5 13 return len > 0 && *s == '#';
3151 18 0 if (PL_dirty) {
3164 3 18 if (g_file_callback_registry) return;
3219 0 17 if (!g_file_callback_registry) return NULL;
3221 14 3 if (svp && SvIOK(*svp)) {
14 0 if (svp && SvIOK(*svp)) {
3248 0 7 if (items != 2) croak("Usage: file::each_line(path, callback)");
3253 7 0 if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) {
0 7 if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) {
3259 1 6 if (idx < 0) {
3265 6 0 old_defsv = DEFSV;
3267 6 0 DEFSV = line_sv;
3270 0 6 PUSH_MULTICALL(block_cv);
3275 1024 9 if (entry->buf_pos < entry->buf_len) {
3279 1018 6 if (newline) {
3293 5 10 if (entry->eof) {
3295 3 2 if (entry->buf_pos < entry->buf_len) {
3309 4 6 if (entry->buf_pos > 0) {
3311 3 1 if (remaining > 0) {
3319 0 10 if (entry->buf_len >= entry->buf_size - 1) {
3327 0 10 if (n < 0) {
3328 0 0 if (errno == EINTR) continue;
3331 5 5 if (n == 0) {
3339 5 0 POP_MULTICALL;
3342 5 0 DEFSV = old_defsv;
3358 0 17 if (items != 2) croak("Usage: file::grep_lines(path, &predicate or $name)");
3365 5 12 if (SvROK(predicate) && SvTYPE(SvRV(predicate)) == SVt_PVCV) {
5 0 if (SvROK(predicate) && SvTYPE(SvRV(predicate)) == SVt_PVCV) {
3370 1 11 if (!fcb) {
3376 0 16 if (idx < 0) {
3382 11 5 if (fcb && fcb->predicate) {
8 3 if (fcb && fcb->predicate) {
3383 72 8 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
3384 41 31 if (fcb->predicate(aTHX_ line)) {
3397 3 5 SV *cb_sv = fcb ? fcb->perl_callback : (SV*)block_cv;
3398 1057 8 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
3403 0 1057 PUSHMARK(SP);
3404 0 1057 XPUSHs(line);
3408 1057 0 if (count > 0) {
3413 26 1031 if (matches) {
3437 6 0 if (items < 1 || items > 2) croak("Usage: file::count_lines(path, [&predicate or $name])");
0 6 if (items < 1 || items > 2) croak("Usage: file::count_lines(path, [&predicate or $name])");
3442 4 2 if (items == 1) {
3454 1 3 if (UNLIKELY(fd < 0)) {
3462 2 3 while ((n = read(fd, buffer, FILE_BUFFER_SIZE)) > 0) {
3465 1008 2 while ((p = memchr(p, '\n', end - p)) != NULL) {
3476 2 1 if (total_read > 0 && last_char != '\n') {
1 1 if (total_read > 0 && last_char != '\n') {
3487 1 1 if (SvROK(predicate) && SvTYPE(SvRV(predicate)) == SVt_PVCV) {
1 0 if (SvROK(predicate) && SvTYPE(SvRV(predicate)) == SVt_PVCV) {
3492 0 1 if (!fcb) {
3498 0 2 if (idx < 0) {
3504 1 1 if (fcb && fcb->predicate) {
1 0 if (fcb && fcb->predicate) {
3505 9 1 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
3506 7 2 if (fcb->predicate(aTHX_ line)) {
3518 0 1 SV *cb_sv = fcb ? fcb->perl_callback : (SV*)block_cv;
3519 9 1 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
3524 0 9 PUSHMARK(SP);
3525 0 9 XPUSHs(line);
3529 9 0 if (n > 0) {
3534 8 1 if (matches) {
3556 0 5 if (items != 2) croak("Usage: file::find_line(path, &predicate or $name)");
3562 4 1 if (SvROK(predicate) && SvTYPE(SvRV(predicate)) == SVt_PVCV) {
4 0 if (SvROK(predicate) && SvTYPE(SvRV(predicate)) == SVt_PVCV) {
3567 0 1 if (!fcb) {
3573 0 5 if (idx < 0) {
3578 1 4 if (fcb && fcb->predicate) {
1 0 if (fcb && fcb->predicate) {
3579 6 0 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
3580 1 5 if (fcb->predicate(aTHX_ line)) {
3593 0 4 SV *cb_sv = fcb ? fcb->perl_callback : (SV*)block_cv;
3594 21 1 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
3599 0 21 PUSHMARK(SP);
3600 0 21 XPUSHs(line);
3604 21 0 if (n > 0) {
3609 3 18 if (matches) {
3630 0 4 if (items != 2) croak("Usage: file::map_lines(path, &callback)");
3636 4 0 if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) {
0 4 if (!SvROK(callback) || SvTYPE(SvRV(callback)) != SVt_PVCV) {
3641 0 4 if (idx < 0) {
3648 27 4 while ((line = file_lines_next(aTHX_ idx)) != &PL_sv_undef) {
3652 0 27 PUSHMARK(SP);
3653 0 27 XPUSHs(sv_2mortal(line));
3657 27 0 if (count > 0) {
3679 0 4 if (items != 2) croak("Usage: file::register_line_callback($name, \\&coderef)");
3684 3 1 if (!SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) {
0 3 if (!SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) {
3693 1 2 if (existing) {
3695 1 0 if (existing->perl_callback) {
3723 1 0 if (g_file_callback_registry) {
3725 14 1 while ((entry = hv_iternext(g_file_callback_registry))) {
3744 0 11 if (items != 1) croak("Usage: file::register_read_hook(\\&coderef)");
3747 11 0 if (!SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) {
0 11 if (!SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) {
3770 0 4 if (items != 1) croak("Usage: file::register_write_hook(\\&coderef)");
3773 4 0 if (!SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) {
0 4 if (!SvROK(coderef) || SvTYPE(SvRV(coderef)) != SVt_PVCV) {
3797 0 40 if (items != 1) croak("Usage: file::clear_hooks($phase)");
3801 26 14 if (strcmp(phase_name, "read") == 0) {
3805 14 0 } else if (strcmp(phase_name, "write") == 0) {
3809 0 0 } else if (strcmp(phase_name, "open") == 0) {
3811 0 0 } else if (strcmp(phase_name, "close") == 0) {
3819 15 40 while (entry) {
3821 15 0 if (entry->perl_callback) {
3839 0 11 if (items != 1) croak("Usage: file::has_hooks($phase)");
3843 6 5 if (strcmp(phase_name, "read") == 0) {
3845 5 1 has = (g_file_read_hook != NULL) || (g_file_hooks[phase] != NULL);
3 2 has = (g_file_read_hook != NULL) || (g_file_hooks[phase] != NULL);
3846 5 0 } else if (strcmp(phase_name, "write") == 0) {
3848 5 0 has = (g_file_write_hook != NULL) || (g_file_hooks[phase] != NULL);
3 2 has = (g_file_write_hook != NULL) || (g_file_hooks[phase] != NULL);
3849 0 0 } else if (strcmp(phase_name, "open") == 0) {
3852 0 0 } else if (strcmp(phase_name, "close") == 0) {
3859 7 4 ST(0) = has ? &PL_sv_yes : &PL_sv_no;
3867 0 2 if (items != 1) croak("Usage: file::atime(path)");
3876 0 2 if (items != 1) croak("Usage: file::ctime(path)");
3885 0 2 if (items != 1) croak("Usage: file::mode(path)");
3896 0 4 if (items != 1) croak("Usage: File::Raw::stat(path)");
3899 1 3 if (result == NULL) {
3910 0 4 if (items != 1) croak("Usage: file::is_link(path)");
3912 1 3 ST(0) = file_is_link_internal(path) ? &PL_sv_yes : &PL_sv_no;
3919 0 0 if (items != 1) croak("Usage: file::is_executable(path)");
3921 0 0 ST(0) = file_is_executable_internal(path) ? &PL_sv_yes : &PL_sv_no;
3929 0 4 if (items != 1) croak("Usage: file::unlink(path)");
3931 2 2 ST(0) = file_unlink_internal(path) ? &PL_sv_yes : &PL_sv_no;
3939 0 3 if (items != 2) croak("Usage: file::copy(src, dst)");
3942 2 1 ST(0) = file_copy_internal(aTHX_ src, dst) ? &PL_sv_yes : &PL_sv_no;
3950 0 3 if (items != 2) croak("Usage: file::move(src, dst)");
3953 2 1 ST(0) = file_move_internal(aTHX_ src, dst) ? &PL_sv_yes : &PL_sv_no;
3960 0 2 if (items != 1) croak("Usage: file::touch(path)");
3962 2 0 ST(0) = file_touch_internal(path) ? &PL_sv_yes : &PL_sv_no;
3968 0 1 if (items > 1) croak("Usage: file::clear_stat_cache() or file::clear_stat_cache(path)");
3970 0 1 if (items == 1 && SvOK(ST(0))) {
0 0 if (items == 1 && SvOK(ST(0))) {
3985 0 1 if (items != 2) croak("Usage: file::chmod(path, mode)");
3988 1 0 ST(0) = file_chmod_internal(path, mode) ? &PL_sv_yes : &PL_sv_no;
3996 12 0 if (items < 1 || items > 2) croak("Usage: file::mkdir(path, [mode])");
0 12 if (items < 1 || items > 2) croak("Usage: file::mkdir(path, [mode])");
3998 0 12 if (items > 1) mode = SvIV(ST(1));
3999 8 4 ST(0) = file_mkdir_internal(path, mode) ? &PL_sv_yes : &PL_sv_no;
4006 0 6 if (items != 1) croak("Usage: file::rmdir(path)");
4008 2 4 ST(0) = file_rmdir_internal(path) ? &PL_sv_yes : &PL_sv_no;
4016 0 5 if (items != 1) croak("Usage: file::readdir(path)");
4027 0 12 if (items != 1) croak("Usage: file::basename(path)");
4036 0 10 if (items != 1) croak("Usage: file::dirname(path)");
4045 0 13 if (items != 1) croak("Usage: file::extname(path)");
4056 0 11 if (items < 1) croak("Usage: file::join(part1, part2, ...)");
4059 26 11 for (i = 0; i < items; i++) {
4077 0 1 if (items != 1) croak("Usage: file_mkpath(path)");
4079 0 1 if (path_len >= sizeof(buf)) croak("Path too long");
4081 35 1 for (i = 0; i <= path_len; i++) {
4082 34 1 if (i == path_len || path[i] == '/' || path[i] == '\\') {
30 4 if (i == path_len || path[i] == '/' || path[i] == '\\') {
0 30 if (i == path_len || path[i] == '/' || path[i] == '\\') {
4083 1 4 if (i == 0) {
4093 0 4 if (i == 2 && buf[1] == ':') continue;
0 0 if (i == 2 && buf[1] == ':') continue;
4095 2 2 if (!file_is_dir_internal(buf)) {
4096 2 0 if (file_mkdir_internal(buf, 0755))
4102 0 1 ST(0) = created || file_is_dir_internal(path) ? &PL_sv_yes : &PL_sv_no;
0 0 ST(0) = created || file_is_dir_internal(path) ? &PL_sv_yes : &PL_sv_no;
4111 0 2 if (!file_is_dir_internal(path)) {
4118 1 2 for (i = 0; i < len; i++) {
4120 1 0 if (sv) {
4130 1 0 if (file_is_dir_internal(child)) {
4148 0 1 if (items != 1) croak("Usage: file_rm_rf(path)");
4161 6 0 if (items < 1 || items > 2) croak("Usage: file::head(path, [n])");
0 6 if (items < 1 || items > 2) croak("Usage: file::head(path, [n])");
4163 4 2 if (items > 1) n = SvIV(ST(1));
4174 6 0 if (items < 1 || items > 2) croak("Usage: file::tail(path, [n])");
0 6 if (items < 1 || items > 2) croak("Usage: file::tail(path, [n])");
4176 4 2 if (items > 1) n = SvIV(ST(1));
4186 0 14 if (items != 2) croak("Usage: file::atomic_spew(path, data)");
4188 14 0 ST(0) = file_atomic_spew_internal(aTHX_ path, ST(1)) ? &PL_sv_yes : &PL_sv_no;
4199 0 0 if (items != 1) croak("Usage: file_slurp($path)");
4208 0 0 if (items != 2) croak("Usage: file_spew($path, $data)");
4210 0 0 if (file_spew_internal(aTHX_ path, ST(1))) {
4221 0 0 if (items != 1) croak("Usage: file_exists($path)");
4223 0 0 ST(0) = file_exists_internal(path) ? &PL_sv_yes : &PL_sv_no;
4230 0 0 if (items != 1) croak("Usage: file_size($path)");
4239 0 0 if (items != 1) croak("Usage: file_is_file($path)");
4241 0 0 ST(0) = file_is_file_internal(path) ? &PL_sv_yes : &PL_sv_no;
4248 0 0 if (items != 1) croak("Usage: file_is_dir($path)");
4250 0 0 ST(0) = file_is_dir_internal(path) ? &PL_sv_yes : &PL_sv_no;
4259 0 0 if (items != 1) croak("Usage: file_lines($path)");
4263 0 0 if (content == &PL_sv_undef) {
4277 0 0 if (items != 1) croak("Usage: file_unlink($path)");
4279 0 0 ST(0) = file_unlink_internal(path) ? &PL_sv_yes : &PL_sv_no;
4286 0 0 if (items != 1) croak("Usage: file_mkdir($path)");
4288 0 0 ST(0) = file_mkdir_internal(path, 0755) ? &PL_sv_yes : &PL_sv_no;
4295 0 0 if (items != 1) croak("Usage: file_rmdir($path)");
4297 0 0 ST(0) = file_rmdir_internal(path) ? &PL_sv_yes : &PL_sv_no;
4304 0 0 if (items != 1) croak("Usage: file_touch($path)");
4306 0 0 ST(0) = file_touch_internal(path) ? &PL_sv_yes : &PL_sv_no;
4312 0 0 if (items > 1) croak("Usage: file_clear_stat_cache() or file_clear_stat_cache($path)");
4314 0 0 if (items == 1 && SvOK(ST(0))) {
0 0 if (items == 1 && SvOK(ST(0))) {
4328 0 0 if (items != 1) croak("Usage: file_basename($path)");
4337 0 0 if (items != 1) croak("Usage: file_dirname($path)");
4346 0 0 if (items != 1) croak("Usage: file_extname($path)");
4355 0 0 if (items != 1) croak("Usage: file_mtime($path)");
4364 0 0 if (items != 1) croak("Usage: file_atime($path)");
4373 0 0 if (items != 1) croak("Usage: file_ctime($path)");
4382 0 0 if (items != 1) croak("Usage: file_mode($path)");
4391 0 0 if (items != 1) croak("Usage: file_is_link($path)");
4393 0 0 ST(0) = file_is_link_internal(path) ? &PL_sv_yes : &PL_sv_no;
4400 0 0 if (items != 1) croak("Usage: file_is_readable($path)");
4402 0 0 ST(0) = file_is_readable_internal(path) ? &PL_sv_yes : &PL_sv_no;
4409 0 0 if (items != 1) croak("Usage: file_is_writable($path)");
4411 0 0 ST(0) = file_is_writable_internal(path) ? &PL_sv_yes : &PL_sv_no;
4418 0 0 if (items != 1) croak("Usage: file_is_executable($path)");
4420 0 0 ST(0) = file_is_executable_internal(path) ? &PL_sv_yes : &PL_sv_no;
4428 0 0 if (items != 1) croak("Usage: file_readdir($path)");
4438 0 0 if (items != 1) croak("Usage: file_slurp_raw($path)");
4448 0 0 if (items != 2) croak("Usage: file_copy($src, $dst)");
4451 0 0 ST(0) = file_copy_internal(aTHX_ src, dst) ? &PL_sv_yes : &PL_sv_no;
4459 0 0 if (items != 2) croak("Usage: file_move($src, $dst)");
4462 0 0 ST(0) = file_move_internal(aTHX_ src, dst) ? &PL_sv_yes : &PL_sv_no;
4470 0 0 if (items != 2) croak("Usage: file_chmod($path, $mode)");
4473 0 0 ST(0) = file_chmod_internal(path, mode) ? &PL_sv_yes : &PL_sv_no;
4480 0 0 if (items != 2) croak("Usage: file_append($path, $data)");
4482 0 0 ST(0) = file_append_internal(aTHX_ path, ST(1)) ? &PL_sv_yes : &PL_sv_no;
4489 0 0 if (items != 2) croak("Usage: file_atomic_spew($path, $data)");
4491 0 0 ST(0) = file_atomic_spew_internal(aTHX_ path, ST(1)) ? &PL_sv_yes : &PL_sv_no;
4548 15 132 if (e->args == 0) {
4553 103 29 } else if (e->args == 1) {
4562 132 4 for (i = 0; import_funcs[i].name != NULL; i++) {
4574 25 0 pkg = CopSTASHPV(PL_curcop);
25 0 pkg = CopSTASHPV(PL_curcop);
25 0 pkg = CopSTASHPV(PL_curcop);
0 25 pkg = CopSTASHPV(PL_curcop);
0 0 pkg = CopSTASHPV(PL_curcop);
25 0 pkg = CopSTASHPV(PL_curcop);
0 25 pkg = CopSTASHPV(PL_curcop);
4577 17 8 if (items <= 1) {
4582 19 4 for (i = 1; i < items; i++) {
4587 7 12 if ((len == 4 && strEQ(arg, ":all")) ||
5 2 if ((len == 4 && strEQ(arg, ":all")) ||
4588 6 11 (len == 6 && strEQ(arg, "import"))) {
2 4 (len == 6 && strEQ(arg, "import"))) {
4594 290 0 for (j = 0; import_funcs[j].name != NULL; j++) {
4595 15 275 if (strEQ(arg, import_funcs[j].name)) {
4602 0 15 if (import_funcs[j].name == NULL) {