1 /* Control an ELF file desrciptor. 2 Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc. 3 Written 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 <unistd.h> 23 24 #include "libelfP.h" 25 26 27 int 28 elf_cntl (elf, cmd) 29 Elf *elf; 30 Elf_Cmd cmd; 31 { 32 int result = 0; 33 34 if (elf == NULL) 35 return -1; 36 37 if (elf->fildes == -1) 38 { 39 __libelf_seterrno (ELF_E_INVALID_HANDLE); 40 return -1; 41 } 42 43 rwlock_wrlock (elf->lock); 44 45 switch (cmd) 46 { 47 case ELF_C_FDREAD: 48 /* If not all of the file is in the memory read it now. */ 49 if (elf->map_address == NULL && __libelf_readall (elf) == NULL) 50 { 51 /* We were not able to read everything. */ 52 result = -1; 53 break; 54 } 55 /* FALLTHROUGH */ 56 57 case ELF_C_FDDONE: 58 /* Mark the file descriptor as not usable. */ 59 elf->fildes = -1; 60 break; 61 62 default: 63 __libelf_seterrno (ELF_E_INVALID_CMD); 64 result = -1; 65 break; 66 } 67 68 rwlock_unlock (elf->lock); 69 70 return result; 71 } 72