tools/elf4rom/libs/libelf-0.8.10/lib/flag.c
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 /*
       
     2 flag.c - implementation of the elf_flag*(3) functions.
       
     3 Copyright (C) 1995 - 1998 Michael Riepe
       
     4 
       
     5 This library is free software; you can redistribute it and/or
       
     6 modify it under the terms of the GNU Library General Public
       
     7 License as published by the Free Software Foundation; either
       
     8 version 2 of the License, or (at your option) any later version.
       
     9 
       
    10 This library is distributed in the hope that it will be useful,
       
    11 but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    13 Library General Public License for more details.
       
    14 
       
    15 You should have received a copy of the GNU Library General Public
       
    16 License along with this library; if not, write to the Free Software
       
    17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    18 */
       
    19 
       
    20 #include <private.h>
       
    21 
       
    22 #ifndef lint
       
    23 static const char rcsid[] = "@(#) $Id: flag.c,v 1.6 2005/05/21 15:39:22 michael Exp $";
       
    24 #endif /* lint */
       
    25 
       
    26 static unsigned
       
    27 _elf_flag(unsigned *f, Elf_Cmd cmd, unsigned flags) {
       
    28     if (cmd == ELF_C_SET) {
       
    29 	return *f |= flags;
       
    30     }
       
    31     if (cmd == ELF_C_CLR) {
       
    32 	return *f &= ~flags;
       
    33     }
       
    34     seterr(ERROR_INVALID_CMD);
       
    35     return 0;
       
    36 }
       
    37 
       
    38 unsigned
       
    39 elf_flagdata(Elf_Data *data, Elf_Cmd cmd, unsigned flags) {
       
    40     Scn_Data *sd = (Scn_Data*)data;
       
    41 
       
    42     if (!sd) {
       
    43 	return 0;
       
    44     }
       
    45     elf_assert(sd->sd_magic == DATA_MAGIC);
       
    46     return _elf_flag(&sd->sd_data_flags, cmd, flags);
       
    47 }
       
    48 
       
    49 unsigned
       
    50 elf_flagehdr(Elf *elf, Elf_Cmd cmd, unsigned flags) {
       
    51     if (!elf) {
       
    52 	return 0;
       
    53     }
       
    54     elf_assert(elf->e_magic == ELF_MAGIC);
       
    55     return _elf_flag(&elf->e_ehdr_flags, cmd, flags);
       
    56 }
       
    57 
       
    58 unsigned
       
    59 elf_flagelf(Elf *elf, Elf_Cmd cmd, unsigned flags) {
       
    60     if (!elf) {
       
    61 	return 0;
       
    62     }
       
    63     elf_assert(elf->e_magic == ELF_MAGIC);
       
    64     return _elf_flag(&elf->e_elf_flags, cmd, flags);
       
    65 }
       
    66 
       
    67 unsigned
       
    68 elf_flagphdr(Elf *elf, Elf_Cmd cmd, unsigned flags) {
       
    69     if (!elf) {
       
    70 	return 0;
       
    71     }
       
    72     elf_assert(elf->e_magic == ELF_MAGIC);
       
    73     return _elf_flag(&elf->e_phdr_flags, cmd, flags);
       
    74 }
       
    75 
       
    76 unsigned
       
    77 elf_flagscn(Elf_Scn *scn, Elf_Cmd cmd, unsigned flags) {
       
    78     if (!scn) {
       
    79 	return 0;
       
    80     }
       
    81     elf_assert(scn->s_magic == SCN_MAGIC);
       
    82     return _elf_flag(&scn->s_scn_flags, cmd, flags);
       
    83 }
       
    84 
       
    85 unsigned
       
    86 elf_flagshdr(Elf_Scn *scn, Elf_Cmd cmd, unsigned flags) {
       
    87     if (!scn) {
       
    88 	return 0;
       
    89     }
       
    90     elf_assert(scn->s_magic == SCN_MAGIC);
       
    91     return _elf_flag(&scn->s_shdr_flags, cmd, flags);
       
    92 }