• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Update library in table at the given index.
2    Copyright (C) 2004 Red Hat, Inc.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2004.
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 <gelf.h>
23 #include <stdlib.h>
24 #include <string.h>
25 
26 #include "libelfP.h"
27 
28 
29 int
gelf_update_lib(data,ndx,src)30 gelf_update_lib (data, ndx, src)
31      Elf_Data *data;
32      int ndx;
33      GElf_Lib *src;
34 {
35   if (data == NULL)
36     return 0;
37 
38   if (unlikely (ndx < 0))
39     {
40       __libelf_seterrno (ELF_E_INVALID_INDEX);
41       return 0;
42     }
43 
44   Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
45   if (unlikely (data_scn->d.d_type != ELF_T_LIB))
46     {
47       /* The type of the data better should match.  */
48       __libelf_seterrno (ELF_E_DATA_MISMATCH);
49       return 0;
50     }
51 
52   Elf_Scn *scn = data_scn->s;
53   rwlock_wrlock (scn->elf->lock);
54 
55   /* Check whether we have to resize the data buffer.  */
56   int result = 0;
57   if (unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size))
58     __libelf_seterrno (ELF_E_INVALID_INDEX);
59   else
60     {
61       ((Elf64_Lib *) data_scn->d.d_buf)[ndx] = *src;
62 
63       result = 1;
64 
65       /* Mark the section as modified.  */
66       scn->flags |= ELF_F_DIRTY;
67     }
68 
69   rwlock_unlock (scn->elf->lock);
70 
71   return result;
72 }
73