python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / development / libraries / glibc / nix-locale-archive.patch
blob2fedf2a7a7dbdc41bafb3c00592cf249607409cc
1 diff --git a/locale/loadarchive.c b/locale/loadarchive.c
2 index 512769eaec..171dbb4ad9 100644
3 --- a/locale/loadarchive.c
4 +++ b/locale/loadarchive.c
5 @@ -123,6 +123,23 @@ calculate_head_size (const struct locarhead *h)
6 return MAX (namehash_end, MAX (string_end, locrectab_end));
9 +static int
10 +open_locale_archive (void)
12 + int fd = -1;
13 + char *versioned_path = getenv ("LOCALE_ARCHIVE_2_27");
14 + char *path = getenv ("LOCALE_ARCHIVE");
15 + if (versioned_path)
16 + fd = __open_nocancel (versioned_path, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
17 + if (path && fd < 0)
18 + fd = __open_nocancel (path, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
19 + if (fd < 0)
20 + fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
21 + if (fd < 0)
22 + fd = __open_nocancel ("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE|O_CLOEXEC);
23 + return fd;
27 /* Find the locale *NAMEP in the locale archive, and return the
28 internalized data structure for its CATEGORY data. If this locale has
29 @@ -202,7 +219,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
30 archmapped = &headmap;
32 /* The archive has never been opened. */
33 - fd = __open_nocancel (archfname, O_RDONLY|O_LARGEFILE|O_CLOEXEC);
34 + fd = open_locale_archive ();
35 if (fd < 0)
36 /* Cannot open the archive, for whatever reason. */
37 return NULL;
38 @@ -397,8 +414,7 @@ _nl_load_locale_from_archive (int category, const char **namep)
39 if (fd == -1)
41 struct __stat64_t64 st;
42 - fd = __open_nocancel (archfname,
43 - O_RDONLY|O_LARGEFILE|O_CLOEXEC);
44 + fd = open_locale_archive();
45 if (fd == -1)
46 /* Cannot open the archive, for whatever reason. */
47 return NULL;
48 diff --git a/locale/programs/locale.c b/locale/programs/locale.c
49 index ca0a95be99..e484783402 100644
50 --- a/locale/programs/locale.c
51 +++ b/locale/programs/locale.c
52 @@ -633,6 +633,24 @@ nameentcmp (const void *a, const void *b)
56 +static int
57 +open_locale_archive (void)
59 + int fd = -1;
60 + char *versioned_path = getenv ("LOCALE_ARCHIVE_2_27");
61 + char *path = getenv ("LOCALE_ARCHIVE");
62 + if (versioned_path)
63 + fd = open64 (versioned_path, O_RDONLY);
64 + if (path && fd < 0)
65 + fd = open64 (path, O_RDONLY);
66 + if (fd < 0)
67 + fd = open64 (ARCHIVE_NAME, O_RDONLY);
68 + if (fd < 0)
69 + fd = open64 ("/usr/lib/locale/locale-archive", O_RDONLY);
70 + return fd;
74 static int
75 write_archive_locales (void **all_datap, char *linebuf)
77 @@ -645,7 +663,7 @@ write_archive_locales (void **all_datap, char *linebuf)
78 int fd, ret = 0;
79 uint32_t cnt;
81 - fd = open64 (ARCHIVE_NAME, O_RDONLY);
82 + fd = open_locale_archive ();
83 if (fd < 0)
84 return 0;
86 diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
87 index f38e835c52..779a3199fc 100644
88 --- a/locale/programs/locarchive.c
89 +++ b/locale/programs/locarchive.c
90 @@ -117,6 +117,22 @@ prepare_address_space (int fd, size_t total, size_t *reserved, int *xflags,
94 +static int
95 +open_locale_archive (const char * archivefname, int flags)
97 + int fd = -1;
98 + char *versioned_path = getenv ("LOCALE_ARCHIVE_2_27");
99 + char *path = getenv ("LOCALE_ARCHIVE");
100 + if (versioned_path)
101 + fd = open64 (versioned_path, flags);
102 + if (path && fd < 0)
103 + fd = open64 (path, flags);
104 + if (fd < 0)
105 + fd = open64 (archivefname, flags);
106 + return fd;
110 static void
111 create_archive (const char *archivefname, struct locarhandle *ah)
113 @@ -578,7 +594,7 @@ open_archive (struct locarhandle *ah, bool readonly)
114 while (1)
116 /* Open the archive. We must have exclusive write access. */
117 - fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
118 + fd = open_locale_archive (archivefname, readonly ? O_RDONLY : O_RDWR);
119 if (fd == -1)
121 /* Maybe the file does not yet exist? If we are opening