File: rdwrmmap.c

package info (click to toggle)
elfutils 0.152-1%2Bwheezy1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 13,784 kB
  • sloc: ansic: 72,713; sh: 9,983; yacc: 2,053; makefile: 906; lex: 487; awk: 50; sed: 16
file content (29 lines) | stat: -rw-r--r-- 625 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <errno.h>
#include <error.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <libelf.h>

int
main (int argc __attribute__ ((unused)), char *argv[])
{
  int fd = open (argv[1], O_RDWR);
  if (fd < 0)
    error (2, errno, "open: %s", argv[1]);

  if (elf_version (EV_CURRENT) == EV_NONE)
    error (1, 0, "libelf version mismatch");

  Elf *elf = elf_begin (fd, ELF_C_RDWR_MMAP, NULL);
  if (elf == NULL)
    error (1, 0, "elf_begin: %s", elf_errmsg (-1));

  if (elf_update (elf, ELF_C_WRITE) < 0)
    error (1, 0, "elf_update: %s", elf_errmsg (-1));

  elf_end (elf);
  close (fd);

  return 0;
}