diff options
Diffstat (limited to 'intl')
-rw-r--r-- | intl/localealias.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/intl/localealias.c b/intl/localealias.c index 381264ba03..122b5807f9 100644 --- a/intl/localealias.c +++ b/intl/localealias.c @@ -30,6 +30,9 @@ #include <ctype.h> #include <stdio.h> +#if defined _LIBC || defined HAVE___FSETLOCKING +# include <stdio_ext.h> +#endif #include <sys/types.h> #ifdef __GNUC__ @@ -88,6 +91,7 @@ void free (); # define mempcpy __mempcpy # endif # define HAVE_MEMPCPY 1 +# define HAVE___FSETLOCKING 1 /* We need locking here since we can be called from different places. */ # include <bits/libc-lock.h> @@ -99,6 +103,15 @@ __libc_lock_define_initialized (static, lock); # define internal_function #endif +/* Some optimizations for glibc. */ +#ifdef _LIBC +# define FEOF(fp) feof_unlocked (fp) +# define FGETS(buf, n, fp) fgets_unlocked (buf, n, fp) +#else +# define FEOF(fp) feof (fp) +# define FGETS(buf, n, fp) fgets (buf, n, fp) +#endif + /* For those losing systems which don't have `alloca' we have to add some additional code emulating it. */ #ifdef HAVE_ALLOCA @@ -228,8 +241,13 @@ read_alias_file (fname, fname_len) if (fp == NULL) return 0; +#ifdef HAVE___FSETLOCKING + /* No threads present. */ + __fsetlocking (fp, FSETLOCKING_BYCALLER); +#endif + added = 0; - while (!feof (fp)) + while (!FEOF (fp)) { /* It is a reasonable approach to use a fix buffer here because a) we are only interested in the first two fields @@ -241,7 +259,7 @@ read_alias_file (fname, fname_len) char *value; char *cp; - if (fgets (buf, sizeof buf, fp) == NULL) + if (FGETS (buf, sizeof buf, fp) == NULL) /* EOF reached. */ break; @@ -251,7 +269,7 @@ read_alias_file (fname, fname_len) { char altbuf[BUFSIZ]; do - if (fgets (altbuf, sizeof altbuf, fp) == NULL) + if (FGETS (altbuf, sizeof altbuf, fp) == NULL) /* Make sure the inner loop will be left. The outer loop will exit at the `feof' test. */ break; |