1 /* Return raw section content. 2 Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc. 3 Contributed by Ulrich Drepper <drepper (at) redhat.com>, 1998. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, version 2. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program; if not, write to the Free Software Foundation, 16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 17 18 #ifdef HAVE_CONFIG_H 19 # include <config.h> 20 #endif 21 22 #include <stdlib.h> 23 24 #include "libelfP.h" 25 26 27 Elf_Data * 28 elf_rawdata (scn, data) 29 Elf_Scn *scn; 30 Elf_Data *data; 31 { 32 if (scn == NULL || scn->elf->kind != ELF_K_ELF) 33 { 34 __libelf_seterrno (ELF_E_INVALID_HANDLE); 35 return NULL; 36 } 37 38 /* If `data' is not NULL this means we are not addressing the initial 39 data in the file. But this also means this data is already read 40 (since otherwise it is not possible to have a valid `data' pointer) 41 and all the data structures are initialized as well. In this case 42 we can simply walk the list of data records. */ 43 if (data != NULL 44 || (scn->data_read != 0 && (scn->flags & ELF_F_FILEDATA) == 0)) 45 { 46 /* We don't allow accessing any but the data read from the file 47 as raw. */ 48 __libelf_seterrno (ELF_E_DATA_MISMATCH); 49 return NULL; 50 } 51 52 /* If the data for this section was not yet initialized do it now. */ 53 if (scn->data_read == 0) 54 { 55 /* First thing we do is to read the data from the file. There is 56 always a file (or memory region) associated with this descriptor 57 since otherwise the `data_read' flag would be set. */ 58 if (__libelf_set_rawdata (scn) != 0) 59 /* Something went wrong. The error value is already set. */ 60 return NULL; 61 } 62 63 /* Return the first data element in the list. */ 64 return &scn->rawdata.d; 65 } 66 INTDEF(elf_rawdata) 67