| 607 | } |
| 608 | |
| 609 | int strbuf_getcwd(struct strbuf *sb) |
| 610 | { |
| 611 | size_t oldalloc = sb->alloc; |
| 612 | size_t guessed_len = 128; |
| 613 | |
| 614 | for (;; guessed_len *= 2) { |
| 615 | strbuf_grow(sb, guessed_len); |
| 616 | if (getcwd(sb->buf, sb->alloc)) { |
| 617 | strbuf_setlen(sb, strlen(sb->buf)); |
| 618 | return 0; |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | * If getcwd(3) is implemented as a syscall that falls |
| 623 | * back to a regular lookup using readdir(3) etc. then |
| 624 | * we may be able to avoid EACCES by providing enough |
| 625 | * space to the syscall as it's not necessarily bound |
| 626 | * to the same restrictions as the fallback. |
| 627 | */ |
| 628 | if (errno == EACCES && guessed_len < PATH_MAX) |
| 629 | continue; |
| 630 | |
| 631 | if (errno != ERANGE) |
| 632 | break; |
| 633 | } |
| 634 | if (oldalloc == 0) |
| 635 | strbuf_release(sb); |
| 636 | else |
| 637 | strbuf_reset(sb); |
| 638 | return -1; |
| 639 | } |
| 640 | |
| 641 | #ifdef HAVE_GETDELIM |
| 642 | int strbuf_getwholeline(struct strbuf *sb, FILE *fp, int term) |
no test coverage detected