flag.c 2.3 KB

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