diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:29:28 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:29:28 -0800 |
| commit | 441f72d43a9b550baa779fc82f70816da5f74f0e (patch) | |
| tree | 477ac2b54c1ef5b8e25e4255b27bca9469ed3911 /libelf/gelf_rawchunk.c | |
| parent | 7a80622f69812ca3262d2027c07a4ed0c0242945 (diff) | |
| download | platform_external_elfutils-donut-release.tar.gz platform_external_elfutils-donut-release.tar.bz2 platform_external_elfutils-donut-release.zip | |
auto import from //depot/cupcake/@135843android-1.6_r2android-1.6_r1.5android-1.6_r1.4android-1.6_r1.3android-1.6_r1.2android-1.6_r1.1android-1.6_r1donut-release2donut-release
Diffstat (limited to 'libelf/gelf_rawchunk.c')
| -rw-r--r-- | libelf/gelf_rawchunk.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libelf/gelf_rawchunk.c b/libelf/gelf_rawchunk.c new file mode 100644 index 00000000..667f3013 --- /dev/null +++ b/libelf/gelf_rawchunk.c @@ -0,0 +1,71 @@ +/* Retrieve uninterpreted chunk of the file contents. + Copyright (C) 2002 Red Hat, Inc. + Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, version 2. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <libelf.h> +#include <stddef.h> +#include <stdlib.h> +#include <unistd.h> + +#include "libelfP.h" + + +char * +gelf_rawchunk (elf, offset, size) + Elf *elf; + GElf_Off offset; + GElf_Word size; +{ + if (elf == NULL) + { + /* No valid descriptor. */ + __libelf_seterrno (ELF_E_INVALID_HANDLE); + return NULL; + } + + if (offset >= elf->maximum_size + || offset + size >= elf->maximum_size + || offset + size < offset) + { + /* Invalid request. */ + __libelf_seterrno (ELF_E_INVALID_OP); + return NULL; + } + + /* If the file is mmap'ed return an appropriate pointer. */ + if (elf->map_address != NULL) + return (char *) elf->map_address + elf->start_offset + offset; + + /* We allocate the memory and read the data from the file. */ + char *result = (char *) malloc (size); + if (result == NULL) + __libelf_seterrno (ELF_E_NOMEM); + else + /* Read the file content. */ + if ((size_t) pread (elf->fildes, result, size, elf->start_offset + offset) + != size) + { + /* Something went wrong. */ + __libelf_seterrno (ELF_E_READ_ERROR); + free (result); + } + + return result; +} |
