]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/generic/dl-cache.h
Update.
[thirdparty/glibc.git] / sysdeps / generic / dl-cache.h
1 /* Support for reading /etc/ld.so.cache files written by Linux ldconfig.
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
10 The GNU C 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 the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #ifndef _DL_CACHE_DEFAULT_ID
21 # define _DL_CACHE_DEFAULT_ID 3
22 #endif
23
24 #ifndef _dl_cache_check_flags
25 # define _dl_cache_check_flags(flags) \
26 ((flags) == 1 || (flags) == _DL_CACHE_DEFAULT_ID)
27 #endif
28
29 #ifndef LD_SO_CACHE
30 # define LD_SO_CACHE SYSCONFDIR "/ld.so.cache"
31 #endif
32
33 #define CACHEMAGIC "ld.so-1.7.0"
34
35 /* libc5 and glibc 2.0/2.1 use the same format. For glibc 2.2 another
36 format has been added in a compatible way:
37 The beginning of the string table is used for the new table:
38 old_magic
39 nlibs
40 libs[0]
41 ...
42 libs[nlibs-1]
43 pad, new magic needs to be aligned
44 - this is string[0] for the old format
45 new magic - this is string[0] for the new format
46 newnlibs
47 ...
48 newlibs[0]
49 ...
50 newlibs[newnlibs-1]
51 string 1
52 string 2
53 ...
54 */
55 struct file_entry
56 {
57 int flags; /* This is 1 for an ELF library. */
58 unsigned int key, value; /* String table indices. */
59 };
60
61 struct cache_file
62 {
63 char magic[sizeof CACHEMAGIC - 1];
64 unsigned int nlibs;
65 struct file_entry libs[0];
66 };
67
68 #define CACHEMAGIC_NEW "glibc-ld.so.cache"
69 #define CACHE_VERSION "1.0"
70
71
72 struct file_entry_new
73 {
74 int flags; /* This is 1 for an ELF library. */
75 unsigned int key, value; /* String table indices. */
76 unsigned long hwcap; /* Hwcap entry. */
77 };
78
79 struct cache_file_new
80 {
81 char magic[sizeof CACHEMAGIC_NEW - 1];
82 char version[sizeof CACHE_VERSION - 1];
83 unsigned int nlibs; /* Number of entries. */
84 unsigned int len_strings; /* Size of string table. */
85 unsigned int unused[4]; /* Leave space for future extensions. */
86 struct file_entry_new libs[0]; /* Entries describing libraries. */
87 /* After this the string table of size len_strings is found. */
88 };
89
90 /* Used to align cache_file_new. */
91 #define ALIGN_CACHE(addr) \
92 (((addr) + __alignof__ (struct cache_file_new) -1) \
93 & (~(__alignof__ (struct cache_file_new) - 1)))
94
95 static int
96 _dl_cache_libcmp (const char *p1, const char *p2)
97 {
98 while (*p1 != '\0')
99 {
100 if (*p1 >= '0' && *p1 <= '9')
101 {
102 if (*p2 >= '0' && *p2 <= '9')
103 {
104 /* Must compare this numerically. */
105 int val1;
106 int val2;
107
108 val1 = *p1++ - '0';
109 val2 = *p2++ - '0';
110 while (*p1 >= '0' && *p1 <= '9')
111 val1 = val1 * 10 + *p1++ - '0';
112 while (*p2 >= '0' && *p2 <= '9')
113 val2 = val2 * 10 + *p2++ - '0';
114 if (val1 != val2)
115 return val1 - val2;
116 }
117 else
118 return 1;
119 }
120 else if (*p2 >= '0' && *p2 <= '9')
121 return -1;
122 else if (*p1 != *p2)
123 return *p1 - *p2;
124 else
125 {
126 ++p1;
127 ++p2;
128 }
129 }
130 return *p1 - *p2;
131 }