11 #include "../locale/hashval.h"
13 const char *alias_file
= DATADIR
"/locale/locale.alias";
14 const char *locar_file
= PREFIX
"/lib/locale/locale-archive";
15 const char *loc_path
= PREFIX
"/lib/locale/";
18 int max_locarchive_open_retry
= 10;
19 const char *output_prefix
;
22 is_prime (unsigned long candidate
)
24 /* No even number and none less than 10 will be passed here. */
25 unsigned long int divn
= 3;
26 unsigned long int sq
= divn
* divn
;
28 while (sq
< candidate
&& candidate
% divn
!= 0)
35 return candidate
% divn
!= 0;
39 next_prime (unsigned long seed
)
41 /* Make it definitely odd. */
44 while (!is_prime (seed
))
50 /* xmalloc is only used by show_archive_content. */
58 error (int status
, int errnum
, const char *message
, ...)
62 va_start (args
, message
);
64 fprintf (stderr
, "%s: ", program_invocation_name
);
65 vfprintf (stderr
, message
, args
);
68 fprintf (stderr
, ": %s", strerror (errnum
));
72 exit (errnum
== EROFS
? 0 : status
);
75 extern int add_locales_to_archive (size_t nlist
, char *list
[], bool replace
);
83 char *list
[16384], *primary
;
87 dirp
= opendir (loc_path
);
89 error (EXIT_FAILURE
, errno
, "cannot open directory \"%s\"", loc_path
);
91 primary
= getenv ("LC_ALL");
93 primary
= getenv ("LANG");
96 if (strncmp (primary
, "ja", 2) != 0
97 && strncmp (primary
, "ko", 2) != 0
98 && strncmp (primary
, "zh", 2) != 0)
100 char *ptr
= malloc (strlen (primary
) + strlen (".utf8") + 1), *p
, *q
;
106 while (*q
&& *q
!= '.' && *q
!= '@')
109 while (*q
&& *q
!= '@')
111 p
= stpcpy (p
, ".utf8");
118 strcpy (stpcpy (path
, loc_path
), primary
);
119 if (stat64 (path
, &st
) >= 0 && S_ISDIR (st
.st_mode
))
121 list
[cnt
] = strdup (path
);
122 if (list
[cnt
] == NULL
)
123 error (0, errno
, "cannot add file to list \"%s\"", path
);
131 while ((d
= readdir64 (dirp
)) != NULL
)
133 if (strcmp (d
->d_name
, ".") == 0 || strcmp (d
->d_name
, "..") == 0)
136 if (primary
&& strcmp (d
->d_name
, primary
) == 0)
139 strcpy (stpcpy (path
, loc_path
), d
->d_name
);
140 if (stat64 (path
, &st
) < 0)
142 error (0, errno
, "cannot stat \"%s\"", path
);
145 if (! S_ISDIR (st
.st_mode
))
148 error (EXIT_FAILURE
, 0, "too many directories in \"%s\"", loc_path
);
149 list
[cnt
] = strdup (path
);
150 if (list
[cnt
] == NULL
)
152 error (0, errno
, "cannot add file to list \"%s\"", path
);
158 add_locales_to_archive (cnt
, list
, 0);