explain_dirfd_or_die(3)

πŸ“¦
version 1.4.D001 Β· 2 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute

πŸ’– explain_dirfd_or_die β€” the manual page, but make it make sense πŸ’–

okay so bestie, you're here because you want the file descriptor of a directory stream, and you want it done with consequences. this is explain_dirfd_or_die(3), from the Library Functions Manual, and honestly? it's giving "I don't do silent failures." πŸŽ€


✨ NAME ✨

explain_dirfd_or_die β€” grab that directory stream file descriptor, and if it goes wrong, we're gonna talk about it πŸ“’


🌸 SYNOPSIS 🌸

#include <libexplain/dirfd.h>
int explain_dirfd_or_die(DIR *dir);
int explain_dirfd_on_error(DIR *dir);

like. two functions. one of them is dramatic. you already know which. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so explain_dirfd_or_die is the girl who wraps dirfd(3) for you. she calls the dirfd(3) system call, and if it fails? she prints an explanation to stderr (obtained from the explain_dirfd(3) function, no cap) and then she ends the whole process by calling exit(EXIT_FAILURE). no coming back from that. periodt. πŸ’€

and then there's explain_dirfd_on_error, her chiller sister. she also calls the dirfd(3) system call, and on failure she also prints an explanation to stderr obtained from the explain_dirfd(3) function β€” but she still returns to you. she's not gonna ghost your process. she just tells you what happened and hands the problem back. 🫢

  • dir β€” the dir, exactly as to be passed to the dirfd(3) system call. don't get cute with it, just pass it through exactly. ✨

πŸ’œ RETURN VALUE πŸ’œ

explain_dirfd_or_die only returns on success β€” peep dirfd(3) if you want the details. on failure it prints an explanation and exits, meaning it does not return. at all. ever. that's the whole bit. 😭

explain_dirfd_on_error always returns the value return by the wrapped dirfd(3) system call. always. she's consistent like that. πŸ‘‘


πŸ“ EXAMPLE πŸ“

the explain_dirfd_or_die function is intended to be used in a fashion similar to the following example:

int result = explain_dirfd_or_die(dir);

see? iconic. one line. main character energy. πŸ’…βœ¨


🌈 SEE ALSO 🌈


libexplain version 1.4 Copyright (C) 2009 Peter Miller

and that's the whole page bestie, you ate πŸ’– go forth and get that directory stream file descriptor, and remember: if it fails, at least it'll fail loudly. bye babes πŸ¦‹πŸŒΈβœ¨

πŸ“¦ where this page comes from