Home | History | Annotate | Line # | Download | only in libintl
textdomain.c revision 1.1
      1  1.1  itojun /*	$NetBSD: textdomain.c,v 1.1 2000/10/31 10:45:04 itojun Exp $	*/
      2  1.1  itojun 
      3  1.1  itojun /*-
      4  1.1  itojun  * Copyright (c) 2000 Citrus Project,
      5  1.1  itojun  * All rights reserved.
      6  1.1  itojun  *
      7  1.1  itojun  * Redistribution and use in source and binary forms, with or without
      8  1.1  itojun  * modification, are permitted provided that the following conditions
      9  1.1  itojun  * are met:
     10  1.1  itojun  * 1. Redistributions of source code must retain the above copyright
     11  1.1  itojun  *    notice, this list of conditions and the following disclaimer.
     12  1.1  itojun  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  itojun  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  itojun  *    documentation and/or other materials provided with the distribution.
     15  1.1  itojun  *
     16  1.1  itojun  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.1  itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.1  itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.1  itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.1  itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.1  itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.1  itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1  itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.1  itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.1  itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.1  itojun  * SUCH DAMAGE.
     27  1.1  itojun  */
     28  1.1  itojun 
     29  1.1  itojun #include <sys/cdefs.h>
     30  1.1  itojun #if defined(LIBC_SCCS) && !defined(lint)
     31  1.1  itojun __RCSID("$NetBSD: textdomain.c,v 1.1 2000/10/31 10:45:04 itojun Exp $");
     32  1.1  itojun #endif /* LIBC_SCCS and not lint */
     33  1.1  itojun 
     34  1.1  itojun #include <sys/types.h>
     35  1.1  itojun #include <sys/param.h>
     36  1.1  itojun 
     37  1.1  itojun #include <stdio.h>
     38  1.1  itojun #include <string.h>
     39  1.1  itojun #include <libintl.h>
     40  1.1  itojun #include "libintl_local.h"
     41  1.1  itojun #include "pathnames.h"
     42  1.1  itojun 
     43  1.1  itojun static char dpath[PATH_MAX];
     44  1.1  itojun static char dname[PATH_MAX];	/*XXX*/
     45  1.1  itojun const char *__domainpath = _PATH_TEXTDOMAIN;
     46  1.1  itojun const char *__domainname;
     47  1.1  itojun 
     48  1.1  itojun /*
     49  1.1  itojun  * set the default domainname for dcngettext() and friends.
     50  1.1  itojun  */
     51  1.1  itojun char *
     52  1.1  itojun textdomain(domainname)
     53  1.1  itojun 	const char *domainname;
     54  1.1  itojun {
     55  1.1  itojun 
     56  1.1  itojun 	return bindtextdomain(domainname, _PATH_TEXTDOMAIN);
     57  1.1  itojun }
     58  1.1  itojun 
     59  1.1  itojun char *
     60  1.1  itojun bindtextdomain(domainname, dirname)
     61  1.1  itojun 	const char *domainname;
     62  1.1  itojun 	const char *dirname;
     63  1.1  itojun {
     64  1.1  itojun 
     65  1.1  itojun 	if (strlen(dirname) + 1 > sizeof(dpath))
     66  1.1  itojun 		return NULL;
     67  1.1  itojun 	/* disallow relative path */
     68  1.1  itojun 	if (dirname[0] != '/')
     69  1.1  itojun 		return NULL;
     70  1.1  itojun 
     71  1.1  itojun 	if (strlen(domainname) + 1 > sizeof(dname))
     72  1.1  itojun 		return NULL;
     73  1.1  itojun 
     74  1.1  itojun 	strlcpy(dpath, dirname, sizeof(dpath));
     75  1.1  itojun 	__domainpath = dpath;
     76  1.1  itojun 	strlcpy(dname, domainname, sizeof(dname));
     77  1.1  itojun 	__domainname = dname;
     78  1.1  itojun 
     79  1.1  itojun 	/* LINTED const cast */
     80  1.1  itojun 	return (char *)domainname;
     81  1.1  itojun }
     82  1.1  itojun 
     83  1.1  itojun char *
     84  1.1  itojun bind_textdomain_codeset(domainname, codeset)
     85  1.1  itojun 	const char *domainname;
     86  1.1  itojun 	const char *codeset;
     87  1.1  itojun {
     88  1.1  itojun 
     89  1.1  itojun 	/* yet to be done - always fail */
     90  1.1  itojun 	return NULL;
     91  1.1  itojun }
     92