OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [sys/] [linux/] [intl/] [textdomain.c] - Blame information for rev 357

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/* Implementation of the textdomain(3) function.
2
   Copyright (C) 1995-1998, 2000, 2001 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 Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the 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
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
#ifdef HAVE_CONFIG_H
21
# include <config.h>
22
#endif
23
 
24
#if defined STDC_HEADERS || defined _LIBC
25
# include <stdlib.h>
26
#endif
27
 
28
#if defined STDC_HEADERS || defined HAVE_STRING_H || defined _LIBC
29
# include <string.h>
30
#else
31
# include <strings.h>
32
# ifndef memcpy
33
#  define memcpy(Dst, Src, Num) (bcopy (Src, Dst, Num), (Dst))
34
# endif
35
#endif
36
 
37
#ifdef _LIBC
38
# include <libintl.h>
39
#else
40
# include "libgnuintl.h"
41
#endif
42
#include "gettextP.h"
43
 
44
#ifdef _LIBC
45
/* We have to handle multi-threaded applications.  */
46
# include <bits/libc-lock.h>
47
#else
48
/* Provide dummy implementation if this is outside glibc.  */
49
# define __libc_rwlock_define(CLASS, NAME)
50
# define __libc_rwlock_wrlock(NAME)
51
# define __libc_rwlock_unlock(NAME)
52
#endif
53
 
54
/* The internal variables in the standalone libintl.a must have different
55
   names than the internal variables in GNU libc, otherwise programs
56
   using libintl.a cannot be linked statically.  */
57
#if !defined _LIBC
58
# define _nl_default_default_domain _nl_default_default_domain__
59
# define _nl_current_default_domain _nl_current_default_domain__
60
#endif
61
 
62
/* @@ end of prolog @@ */
63
 
64
/* Name of the default text domain.  */
65
extern const char _nl_default_default_domain[];
66
 
67
/* Default text domain in which entries for gettext(3) are to be found.  */
68
extern const char *_nl_current_default_domain;
69
 
70
 
71
/* Names for the libintl functions are a problem.  They must not clash
72
   with existing names and they should follow ANSI C.  But this source
73
   code is also used in GNU C Library where the names have a __
74
   prefix.  So we have to make a difference here.  */
75
#ifdef _LIBC
76
# define TEXTDOMAIN __textdomain
77
# ifdef _GLIBC
78
#  ifndef strdup
79
#   define strdup(str) __strdup (str)
80
#  endif
81
# endif
82
#else
83
# define TEXTDOMAIN textdomain__
84
#endif
85
 
86
/* Lock variable to protect the global data in the gettext implementation.  */
87
__libc_rwlock_define (extern, _nl_state_lock)
88
 
89
/* Set the current default message catalog to DOMAINNAME.
90
   If DOMAINNAME is null, return the current default.
91
   If DOMAINNAME is "", reset to the default of "messages".  */
92
char *
93
TEXTDOMAIN (domainname)
94
     const char *domainname;
95
{
96
  char *new_domain;
97
  char *old_domain;
98
 
99
  /* A NULL pointer requests the current setting.  */
100
  if (domainname == NULL)
101
    return (char *) _nl_current_default_domain;
102
 
103
  __libc_rwlock_wrlock (_nl_state_lock);
104
 
105
  old_domain = (char *) _nl_current_default_domain;
106
 
107
  /* If domain name is the null string set to default domain "messages".  */
108
  if (domainname[0] == '\0'
109
      || strcmp (domainname, _nl_default_default_domain) == 0)
110
    {
111
      _nl_current_default_domain = _nl_default_default_domain;
112
      new_domain = (char *) _nl_current_default_domain;
113
    }
114
  else if (strcmp (domainname, old_domain) == 0)
115
    /* This can happen and people will use it to signal that some
116
       environment variable changed.  */
117
    new_domain = old_domain;
118
  else
119
    {
120
      /* If the following malloc fails `_nl_current_default_domain'
121
         will be NULL.  This value will be returned and so signals we
122
         are out of core.  */
123
#if defined _LIBC || defined HAVE_STRDUP
124
      new_domain = strdup (domainname);
125
#else
126
      size_t len = strlen (domainname) + 1;
127
      new_domain = (char *) malloc (len);
128
      if (new_domain != NULL)
129
        memcpy (new_domain, domainname, len);
130
#endif
131
 
132
      if (new_domain != NULL)
133
        _nl_current_default_domain = new_domain;
134
    }
135
 
136
  /* We use this possibility to signal a change of the loaded catalogs
137
     since this is most likely the case and there is no other easy we
138
     to do it.  Do it only when the call was successful.  */
139
  if (new_domain != NULL)
140
    {
141
      ++_nl_msg_cat_cntr;
142
 
143
      if (old_domain != new_domain && old_domain != _nl_default_default_domain)
144
        free (old_domain);
145
    }
146
 
147
  __libc_rwlock_unlock (_nl_state_lock);
148
 
149
  return new_domain;
150
}
151
 
152
#ifdef _LIBC
153
/* Alias for function name in GNU C Library.  */
154
weak_alias (__textdomain, textdomain);
155
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.