Skip to content

Commit d9a65b6

Browse files
rscharfegitster
authored andcommitted
setup: use xopen and xdup in sanitize_stdfds
Replace the catch-all error message with specific ones for opening and duplicating by calling the wrappers xopen and xdup. The code becomes easier to follow when error handling is reduced to two letters. Remove the unnecessary mode parameter while at it -- we expect /dev/null to already exist. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit d9a65b6

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

setup.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,11 +1423,9 @@ const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)
14231423
/* if any standard file descriptor is missing open it to /dev/null */
14241424
void sanitize_stdfds(void)
14251425
{
1426-
int fd = open("/dev/null", O_RDWR, 0);
1427-
while (fd != -1 && fd < 2)
1428-
fd = dup(fd);
1429-
if (fd == -1)
1430-
die_errno(_("open /dev/null or dup failed"));
1426+
int fd = xopen("/dev/null", O_RDWR);
1427+
while (fd < 2)
1428+
fd = xdup(fd);
14311429
if (fd > 2)
14321430
close(fd);
14331431
}

0 commit comments

Comments
 (0)