HP-UX Reference (11i v1 00/12) - 3 Library Functions A-M (vol 6)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man3/!!!intro.3c
________________________________________________________________
___ ___
e
elf_begin(3E) elf_begin(3E)
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 3174 3 HP-UX Release 11i: December 2000
___
___