| 748 | } |
| 749 | |
| 750 | int open_nofollow(const char *path, int flags) |
| 751 | { |
| 752 | #ifdef O_NOFOLLOW |
| 753 | int ret = open(path, flags | O_NOFOLLOW); |
| 754 | /* |
| 755 | * NetBSD sets errno to EFTYPE when path is a symlink. The only other |
| 756 | * time this errno occurs when O_REGULAR is used. Since we don't use |
| 757 | * it anywhere we can avoid an lstat here. FreeBSD does the same with |
| 758 | * EMLINK. |
| 759 | */ |
| 760 | # ifdef __NetBSD__ |
| 761 | # define SYMLINK_ERRNO EFTYPE |
| 762 | # elif defined(__FreeBSD__) |
| 763 | # define SYMLINK_ERRNO EMLINK |
| 764 | # endif |
| 765 | # if SYMLINK_ERRNO |
| 766 | if (ret < 0 && errno == SYMLINK_ERRNO) { |
| 767 | errno = ELOOP; |
| 768 | return -1; |
| 769 | } |
| 770 | # undef SYMLINK_ERRNO |
| 771 | # endif |
| 772 | return ret; |
| 773 | #else |
| 774 | struct stat st; |
| 775 | if (lstat(path, &st) < 0) |
| 776 | return -1; |
| 777 | if (S_ISLNK(st.st_mode)) { |
| 778 | errno = ELOOP; |
| 779 | return -1; |
| 780 | } |
| 781 | return open(path, flags); |
| 782 | #endif |
| 783 | } |
| 784 | |
| 785 | int csprng_bytes(void *buf, size_t len, MAYBE_UNUSED unsigned flags) |
| 786 | { |
no outgoing calls
no test coverage detected