HP-UX Reference (11i v2 04/09) - 3 Library Functions A-M (vol 6)
e
elf_begin(3E) elf_begin(3E)
return;
ehdr = elf32_newehdr(elf);
phdr = elf32_newphdr(elf, count);
scn = elf_newscn(elf);
shdr = elf32_getshdr(scn);
data = elf_newdata(scn);
elf_update(elf, ELF_C_WRITE);
elf_end(elf);
Finally, the following outline shows how one might update an existing ELF file. Again, this example is
simplified to show the overall flow.
elf_version(EV_CURRENT);
fildes = open("path/name", O_RDWR);
elf = elf_begin(fildes, ELF_C_RDWR, (Elf *)0);
/* add new or delete old information...*/
close(creat("path/name", 0666));
elf_update(elf, ELF_C_WRITE);
elf_end(elf);
In the example above, the call to creat truncates the file, thus ensuring the resulting file will have the
‘‘right’’ size. Without truncation, the updated file might be as big as the original, even if information were
deleted. The library truncates the file, if it can, with ftruncate (see truncate (2)). Some systems, how-
ever, do not support ftruncate, and the call to creat protects against this. Notice that both file crea-
tion examples open the file with write and read permissions. On systems that support mmap
, the library
uses it to enhance performance, and
mmap requires a readable file descriptor. Although the library can
use a write-only file descriptor, the application will not obtain the performance advantages of mmap
.
SEE ALSO
ar(4), creat(2), elf(3E), elf_cntl(3E), elf_end(3E), elf_getarhdr(3E), elf_getbase(3E), elf_getdata(3E),
elf_getehdr(3E), elf_getphdr(3E), elf_getscn(3E), elf_kind(3E), elf_next(3E), elf_rand(3E), elf_rawfile(3E),
elf_update(3E), elf_version(3E), lseek(2), mmap(2), open(2), truncate(2).
Section 3−−240 Hewlett-Packard Company − 3 − HP-UX 11i Version 2: September 2004