1 /* $NetBSD: src/lib/libc/locale/aliasname.c,v 1.1 2002/02/13 07:45:52 yamt Exp $ */
2 /* $DragonFly: src/lib/libc/locale/aliasname.c,v 1.1 2005/03/16 07:54:41 joerg Exp $ */
5 * Copyright (c)2002 YAMAMOTO Takashi,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "aliasname_local.h"
36 static __inline
int __is_ws(char);
42 return(ch
== ' ' || ch
== '\t');
46 __unaliasname(const char *dbname
, const char *alias
, void *buf
, size_t bufsize
)
49 const char *result
= alias
;
55 _DIAGASSERT(dbname
!= NULL
);
56 _DIAGASSERT(alias
!= NULL
);
57 _DIAGASSERT(buf
!= NULL
);
59 fp
= fopen(dbname
, "r");
63 aliaslen
= strlen(alias
);
68 goto quit
; /* eof or error */
70 _DIAGASSERT(len
!= 0);
72 /* ignore terminating NL */
73 if (p
[len
- 1] == '\n')
76 /* ignore null line and comment */
77 if (len
== 0 || p
[0] == '#')
83 if (memcmp(alias
, p
, aliaslen
))
89 if (len
== 0 || !__is_ws(*p
))
92 /* entry was found here */
98 /* skip white spaces */
102 } while (len
!= 0 && __is_ws(*p
));
107 /* count length of result */
109 while (resultlen
< len
&& !__is_ws(*p
))
112 /* check if space is enough */
113 if (bufsize
< resultlen
+ 1)
116 memcpy(buf
, p
, resultlen
);
117 ((char *)buf
)[resultlen
] = 0;