ELF_GETPHNUM(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… ELF_GETPHNUM πŸ’…

ok so real talk, bestie β€” this one's from the Library Functions Manual, section 3, and it's an libelf situation. buckle up πŸŽ€


✨ NAME ✨

elf_getphnum β€” returns the number of program headers in an ELF file. that's it, that's the whole job. πŸ’–

πŸ“š LIBRARY πŸ“š

ELF Access Library β€” that's libelf, and you link it with -lelf. iconic, no notes. 🫢

🧚 SYNOPSIS 🧚

#include <libelf.h>

int
elf_getphnum(Elf *elf, size_t *phnum);

literally just two args. you got this. πŸ’œ

🌸 DESCRIPTION 🌸

okay first thing, and I need you to hear me: this function is deprecated. not like "kinda old" deprecated β€” like, the manpage itself says please use function elf_getphdrnum(3) instead. so if you're writing new code, go there. this one's for the legacy girlies. πŸ™ˆ

so what does elf_getphnum() even do?? it looks at the descriptor elf and retrieves the number of ELF program headers hanging out with it, then stores that number into the location that argument phnum points to. yes, a pointer pointer situation. classic. ✨

and the reason this routine exists at all: it lets your app uniformly process both normal ELF objects and ELF objects that use extended numbering. so you don't have to sit there doing vibe checks on the header yourself. slay πŸ’…

πŸ”₯ RETURN VALUES πŸ”₯

  • non-zero β†’ it worked, we ate πŸ‘‘
  • 0 β†’ something went wrong, and we're sad about it 😭

πŸ’€ ERRORS πŸ’€

elf_getphnum() can fail with these, so like… know them:

  • [ELF_E_ARGUMENT] β€” a NULL value was passed in for argument elf. bestie. you passed in nothing. 🫠
  • [ELF_E_ARGUMENT] β€” argument elf was not for an ELF file. wrong file, wrong vibe.
  • [ELF_E_ARGUMENT] β€” argument elf lacks an ELF Executable Header. it's giving empty. πŸ’€
  • [ELF_E_HEADER] β€” the ELF Executable Header associated with argument elf was corrupt. not cute, not fixable by us.
  • [ELF_E_SECTION] β€” the section header at index SHN_UNDEF was corrupt. also cursed. πŸ™ˆ
none of these are "try again later" errors, btw β€” they're "your file is broken or your argument is wrong" errors. read them carefully. πŸ’–

πŸ¦‹ SEE ALSO πŸ¦‹

elf(3), elf32_getehdr(3), elf64_getehdr(3), elf_getident(3), elf_getphdrnum(3), elf_getshdrnum(3), elf_getshdrstrndx(3), gelf(3), gelf_getehdr(3)

(and yes, elf_getphdrnum(3) is right there in the list, staring at you, begging you to use it instead. main character energy honestly. ⭐)


that's the whole page, bestie 🌈 this one's shipped on Debian, dated August 5, 2009 β€” so yeah, it's been around a minute. mwah πŸ’‹ 🌸

πŸ“¦ where this page comes from