ELF_GETPHNUM(3)
π 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]β aNULLvalue was passed in for argumentelf. bestie. you passed in nothing. π«[ELF_E_ARGUMENT]β argumentelfwas not for an ELF file. wrong file, wrong vibe.[ELF_E_ARGUMENT]β argumentelflacks an ELF Executable Header. it's giving empty. π[ELF_E_HEADER]β the ELF Executable Header associated with argumentelfwas corrupt. not cute, not fixable by us.[ELF_E_SECTION]β the section header at indexSHN_UNDEFwas 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
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: libelf 15.0.0
- Copyright (c) 2006,2008 Joseph Koshy. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms