elf_rawfile.c revision 4484
17860SN/A/*- 27860SN/A * Copyright (c) 2006 Joseph Koshy 37860SN/A * All rights reserved. 48825Snilay@cs.wisc.edu * 57935SN/A * Redistribution and use in source and binary forms, with or without 67935SN/A * modification, are permitted provided that the following conditions 77935SN/A * are met: 87860SN/A * 1. Redistributions of source code must retain the above copyright 97860SN/A * notice, this list of conditions and the following disclaimer. 107860SN/A * 2. Redistributions in binary form must reproduce the above copyright 119885Sstever@gmail.com * notice, this list of conditions and the following disclaimer in the 128825Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution. 139885Sstever@gmail.com * 149885Sstever@gmail.com * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 158825Snilay@cs.wisc.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 168825Snilay@cs.wisc.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 178825Snilay@cs.wisc.edu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 189449SAli.Saidi@ARM.com * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 199449SAli.Saidi@ARM.com * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 208464SN/A * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 218721SN/A * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 228825Snilay@cs.wisc.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 238825Snilay@cs.wisc.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 247935SN/A * SUCH DAMAGE. 257935SN/A */ 267935SN/A 277935SN/A 287935SN/A#include "libelf.h" 297935SN/A 307935SN/A#include "_libelf.h" 318893Ssaidi@eecs.umich.edu 327860SN/Achar * 339885Sstever@gmail.comelf_rawfile(Elf *e, size_t *sz) 349885Sstever@gmail.com{ 359885Sstever@gmail.com char *ptr; 369885Sstever@gmail.com size_t size; 379885Sstever@gmail.com 387860SN/A size = e ? e->e_rawsize : 0; 397860SN/A ptr = NULL; 409481Snilay@cs.wisc.edu 417860SN/A if (e == NULL) 427860SN/A LIBELF_SET_ERROR(ARGUMENT, 0); 438210SN/A else if ((ptr = e->e_rawfile) == NULL && e->e_cmd == ELF_C_WRITE) 448210SN/A LIBELF_SET_ERROR(SEQUENCE, 0); 457860SN/A 467860SN/A if (sz) 477860SN/A *sz = size; 487860SN/A 499481Snilay@cs.wisc.edu return (ptr); 507860SN/A} 517860SN/A