Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* locale/xlocale.h (struct __locale_struct): New member `__names'.
	* locale/xlocale.c (_nl_C_locobj): Update initializer.
	* locale/global-locale.c (_nl_global_locale): Likewise.
	* locale/duplocale.c (__duplocale): strdup __names elements.
	* locale/freelocale.c (__freelocale): Free __names elements.
	* locale/localename.c (_nl_current_names): Variable removed.
	(__current_locale_name): Use _NL_CURRENT_LOCALE->__names instead.
	* locale/localeinfo.h (_nl_current_names): Removed decl.
	* locale/setlocale.c: Use _nl_global_locale->__names in place of
	_nl_current_names throughout.

	* locale/setlocale.c (setlocale): strdup -> __strdup (not ISO C).

	* sysdeps/gnu/errlist-compat.awk: Emit link_warnings for sys_errlist
	and sys_nerr in the output file.

	* sunrpc/Makefile (rpcgen-cmd): Pass CPP in rpcgen's environment.
	* scripts/cpp: Just use the environment variable.

	* libio/tst-mmap-setvbuf.c (main): Use 'm' fopen flag.
	* libio/tst-mmap-offend.c (do_test): Likewise.
	* libio/tst-mmap-fflushsync.c (do_test): Likewise.
	* libio/tst-mmap-eofsync.c (do_test): Likewise.
	* libio/tst-mmap2-eofsync.c (do_test): Likewise.
  • Loading branch information
Roland McGrath committed Aug 30, 2002
1 parent ccaf730 commit 1ce8aaa
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 61 deletions.
25 changes: 25 additions & 0 deletions ChangeLog
@@ -1,5 +1,30 @@
2002-08-30 Roland McGrath <roland@redhat.com>

* locale/xlocale.h (struct __locale_struct): New member `__names'.
* locale/xlocale.c (_nl_C_locobj): Update initializer.
* locale/global-locale.c (_nl_global_locale): Likewise.
* locale/duplocale.c (__duplocale): strdup __names elements.
* locale/freelocale.c (__freelocale): Free __names elements.
* locale/localename.c (_nl_current_names): Variable removed.
(__current_locale_name): Use _NL_CURRENT_LOCALE->__names instead.
* locale/localeinfo.h (_nl_current_names): Removed decl.
* locale/setlocale.c: Use _nl_global_locale->__names in place of
_nl_current_names throughout.

* locale/setlocale.c (setlocale): strdup -> __strdup (not ISO C).

* sysdeps/gnu/errlist-compat.awk: Emit link_warnings for sys_errlist
and sys_nerr in the output file.

* sunrpc/Makefile (rpcgen-cmd): Pass CPP in rpcgen's environment.
* scripts/cpp: Just use the environment variable.

* libio/tst-mmap-setvbuf.c (main): Use 'm' fopen flag.
* libio/tst-mmap-offend.c (do_test): Likewise.
* libio/tst-mmap-fflushsync.c (do_test): Likewise.
* libio/tst-mmap-eofsync.c (do_test): Likewise.
* libio/tst-mmap2-eofsync.c (do_test): Likewise.

* locale/localename.c: If the current locale is the global locale, use
_nl_current_names; otherwise use the locale object.

Expand Down
2 changes: 1 addition & 1 deletion libio/tst-mmap-eofsync.c
Expand Up @@ -38,7 +38,7 @@ do_test (void)
int result = 0;
int c;

f = fopen (temp_file, "r");
f = fopen (temp_file, "rm");
if (f == NULL)
{
perror (temp_file);
Expand Down
2 changes: 1 addition & 1 deletion libio/tst-mmap-fflushsync.c
Expand Up @@ -38,7 +38,7 @@ do_test (void)
int result = 0;
int c;

f = fopen (temp_file, "r");
f = fopen (temp_file, "rm");
if (f == NULL)
{
perror (temp_file);
Expand Down
2 changes: 1 addition & 1 deletion libio/tst-mmap-offend.c
Expand Up @@ -34,7 +34,7 @@ do_test (void)
{
unsigned char buffer[8192];
int result = 0;
FILE *f = fopen (temp_file, "r");
FILE *f = fopen (temp_file, "rm");
size_t cc;

if (f == NULL)
Expand Down
2 changes: 1 addition & 1 deletion libio/tst-mmap-setvbuf.c
Expand Up @@ -48,7 +48,7 @@ int main (void)
fputs (test, f);
fclose (f);

f = fopen (name, "r");
f = fopen (name, "rm");
if (f == NULL)
{
printf ("%u: cannot fopen temporary file: %m\n", __LINE__);
Expand Down
2 changes: 1 addition & 1 deletion libio/tst-mmap2-eofsync.c
Expand Up @@ -44,7 +44,7 @@ do_test (void)
int result = 0;
int c;

f = fopen (temp_file, "r");
f = fopen (temp_file, "rm");
if (f == NULL)
{
perror (temp_file);
Expand Down
26 changes: 25 additions & 1 deletion locale/duplocale.c
Expand Up @@ -33,15 +33,39 @@ __locale_t
__duplocale (__locale_t dataset)
{
__locale_t result;
int cnt;

/* We modify global data. */
__libc_lock_lock (__libc_setlocale_lock);

/* Get memory. */
result = (__locale_t) malloc (sizeof (struct __locale_struct));

if (result != NULL)
/* Duplicate the names in a separate loop first so we can
bail out if strdup fails and not have touched usage_counts. */
for (cnt = 0; cnt < __LC_LAST; ++cnt)
if (cnt != LC_ALL)
{
if (dataset->__names[cnt] == _nl_C_name)
result->__names[cnt] = _nl_C_name;
else
{
result->__names[cnt] = __strdup (dataset->__names[cnt]);
if (result->__names[cnt] == NULL)
{
while (cnt-- > 0)
if (dataset->__names[cnt] != _nl_C_name)
free ((char *) dataset->__names[cnt]);
free (result);
result = NULL;
break;
}
}
}

if (result != NULL)
{
int cnt;
for (cnt = 0; cnt < __LC_LAST; ++cnt)
if (cnt != LC_ALL)
{
Expand Down
11 changes: 8 additions & 3 deletions locale/freelocale.c
Expand Up @@ -38,9 +38,14 @@ __freelocale (__locale_t dataset)
__libc_lock_lock (__libc_setlocale_lock);

for (cnt = 0; cnt < __LC_LAST; ++cnt)
if (cnt != LC_ALL && dataset->__locales[cnt]->usage_count != UNDELETABLE)
/* We can remove the data. */
_nl_remove_locale (cnt, dataset->__locales[cnt]);
if (cnt != LC_ALL)
{
if (dataset->__locales[cnt]->usage_count != UNDELETABLE)
/* We can remove the data. */
_nl_remove_locale (cnt, dataset->__locales[cnt]);
if (dataset->__names[cnt] != _nl_C_name)
free ((char *) dataset->__names[cnt]);
}

/* Free the locale_t handle itself. */
free (dataset);
Expand Down
8 changes: 8 additions & 0 deletions locale/global-locale.c
Expand Up @@ -44,6 +44,14 @@ struct __locale_struct _nl_global_locale attribute_hidden =
#define DEFINE_CATEGORY(category, category_name, items, a) \
[category] = &_nl_C_##category,
#include "categories.def"
#undef DEFINE_CATEGORY
},
.__names =
{
[LC_ALL] = _nl_C_name,
#define DEFINE_CATEGORY(category, category_name, items, a) \
[category] = _nl_C_name,
#include "categories.def"
#undef DEFINE_CATEGORY
},
.__ctype_b = (const unsigned short int *) _nl_C_LC_CTYPE_class + 128,
Expand Down
4 changes: 0 additions & 4 deletions locale/localeinfo.h
Expand Up @@ -177,10 +177,6 @@ extern const char _nl_POSIX_name[] attribute_hidden;
/* The standard codeset. */
extern const char _nl_C_codeset[] attribute_hidden;

/* Name of current locale for each individual category.
Each is malloc'd unless it is _nl_C_name. */
extern const char *_nl_current_names[] attribute_hidden;

/* This is the internal locale_t object that holds the global locale
controlled by calls to setlocale. A thread's TSD locale pointer
points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect. */
Expand Down
15 changes: 1 addition & 14 deletions locale/localename.c
Expand Up @@ -19,22 +19,9 @@

#include "localeinfo.h"

/* Name of current locale for each individual category.
Each is malloc'd unless it is _nl_C_name. */
const char *_nl_current_names[] attribute_hidden =
{
#define DEFINE_CATEGORY(category, category_name, items, a) \
[category] = _nl_C_name,
#include "categories.def"
#undef DEFINE_CATEGORY
[LC_ALL] = _nl_C_name /* For LC_ALL. */
};

const char *
attribute_hidden
__current_locale_name (int category)
{
return (_NL_CURRENT_LOCALE == &_nl_global_locale
? _nl_current_names[category]
: _NL_CURRENT_LOCALE->__locales[category]->name);
return _NL_CURRENT_LOCALE->__names[category];
}
24 changes: 12 additions & 12 deletions locale/setlocale.c
Expand Up @@ -136,7 +136,7 @@ new_composite_name (int category, const char *newnames[__LC_LAST])
{
const char *name = (category == LC_ALL ? newnames[i] :
category == i ? newnames[0] :
_nl_current_names[i]);
_nl_global_locale.__names[i]);
last_len = strlen (name);
cumlen += _nl_category_name_sizes[i] + 1 + last_len + 1;
if (i > 0 && same && strcmp (name, newnames[0]) != 0)
Expand Down Expand Up @@ -165,7 +165,7 @@ new_composite_name (int category, const char *newnames[__LC_LAST])
/* Add "CATEGORY=NAME;" to the string. */
const char *name = (category == LC_ALL ? newnames[i] :
category == i ? newnames[0] :
_nl_current_names[i]);
_nl_global_locale.__names[i]);
p = __stpcpy (p, _nl_category_names[i]);
*p++ = '=';
p = __stpcpy (p, name);
Expand All @@ -176,17 +176,17 @@ new_composite_name (int category, const char *newnames[__LC_LAST])
}


/* Put NAME in _nl_current_names. */
/* Put NAME in _nl_global_locale.__names. */
static inline void
setname (int category, const char *name)
{
if (_nl_current_names[category] == name)
if (_nl_global_locale.__names[category] == name)
return;

if (_nl_current_names[category] != _nl_C_name)
free ((char *) _nl_current_names[category]);
if (_nl_global_locale.__names[category] != _nl_C_name)
free ((char *) _nl_global_locale.__names[category]);

_nl_current_names[category] = name;
_nl_global_locale.__names[category] = name;
}

/* Put DATA in *_nl_current[CATEGORY]. */
Expand Down Expand Up @@ -216,11 +216,11 @@ setlocale (int category, const char *locale)

/* Does user want name of current locale? */
if (locale == NULL)
return (char *) _nl_current_names[category];
return (char *) _nl_global_locale.__names[category];

if (strcmp (locale, _nl_current_names[category]) == 0)
if (strcmp (locale, _nl_global_locale.__names[category]) == 0)
/* Changing to the same thing. */
return (char *) _nl_current_names[category];
return (char *) _nl_global_locale.__names[category];

/* We perhaps really have to load some data. So we determine the
path in which to look for the data now. The environment variable
Expand Down Expand Up @@ -324,7 +324,7 @@ setlocale (int category, const char *locale)
/* Make a copy of locale name. */
if (newnames[category] != _nl_C_name)
{
newnames[category] = strdup (newnames[category]);
newnames[category] = __strdup (newnames[category]);
if (newnames[category] == NULL)
break;
}
Expand Down Expand Up @@ -389,7 +389,7 @@ setlocale (int category, const char *locale)
/* Make a copy of locale name. */
if (newname[0] != _nl_C_name)
{
newname[0] = strdup (newname[0]);
newname[0] = __strdup (newname[0]);
if (newname[0] == NULL)
goto abort_single;
}
Expand Down
8 changes: 8 additions & 0 deletions locale/xlocale.c
Expand Up @@ -39,6 +39,14 @@ struct __locale_struct _nl_C_locobj attribute_hidden =
#define DEFINE_CATEGORY(category, category_name, items, a) \
[category] = &_nl_C_##category,
#include "categories.def"
#undef DEFINE_CATEGORY
},
.__names =
{
[LC_ALL] = _nl_C_name,
#define DEFINE_CATEGORY(category, category_name, items, a) \
[category] = _nl_C_name,
#include "categories.def"
#undef DEFINE_CATEGORY
},
.__ctype_b = (const unsigned short int *) _nl_C_LC_CTYPE_class + 128,
Expand Down
3 changes: 2 additions & 1 deletion locale/xlocale.h
@@ -1,5 +1,5 @@
/* Definition of locale datatype.
Copyright (C) 1997, 2000 Free Software Foundation, Inc.
Copyright (C) 1997,2000,02 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
Expand Down Expand Up @@ -29,6 +29,7 @@ typedef struct __locale_struct
{
/* Note: LC_ALL is not a valid index into this array. */
struct locale_data *__locales[13]; /* 13 = __LC_LAST. */
const char *__names[13];

/* To increase the speed of this solution we add some special members. */
const unsigned short int *__ctype_b;
Expand Down
24 changes: 4 additions & 20 deletions scripts/cpp
@@ -1,22 +1,6 @@
#! /bin/sh
cpp=`which cpp 2>/dev/null`
if test $? -ne 0; then
if type cpp 2>/dev/null >/dev/null; then
cpp=`type cpp 2>/dev/null | awk '{ print $NF }'`
else
cpp=`gcc -print-file-name=cpp 2>/dev/null`
if test $? -ne 0; then
if test -x /lib/cpp; then
cpp=/lib/cpp
else
echo "cpp not found" 1>&2
exit 1
fi
fi
fi
fi

exec $cpp $*
Local Variables:
mode: sh
End:
# This script is used solely by rpcgen when run by sunrpc/Makefile,
# which passes CPP in the environment to tell us what to run.

exec ${CPP} "$@"
2 changes: 1 addition & 1 deletion sunrpc/Makefile
Expand Up @@ -132,7 +132,7 @@ $(objpfx)rpcgen: $(addprefix $(objpfx),$(rpcgen-objs)) \
$(+link)

# Tell rpcgen where to find the C preprocessor.
rpcgen-cmd = $(built-program-cmd) -Y ../scripts
rpcgen-cmd = CPP='$(CC) -E -x c-header' $(built-program-cmd) -Y ../scripts

# Install the rpc data base file.
$(inst_sysconfdir)/rpc: etc.rpc $(+force)
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/gnu/errlist-compat.awk
Expand Up @@ -113,4 +113,10 @@ versioned_symbol (libc, __sys_errlist_internal, _sys_errlist, %s);\n\
versioned_symbol (libc, _sys_nerr_internal, sys_nerr, %s);\n\
versioned_symbol (libc, __sys_nerr_internal, _sys_nerr, %s);\n", \
lastv, lastv, lastv, lastv;

print "\n\
link_warning (sys_errlist, \"\
`sys_errlist' is deprecated; use `strerror' or `strerror_r' instead\")\n\
link_warning (sys_nerr, \"\
`sys_nerr' is deprecated; use `strerror' or `strerror_r' instead\")";
}

0 comments on commit 1ce8aaa

Please sign in to comment.