4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #pragma weak _catgets = catgets
36 #include <sys/types.h>
39 #include "nlspath_checks.h"
42 catgets(nl_catd catd_st
, int set_id
, int msg_id
, const char *def_str
)
46 struct _cat_set_hdr
*q
;
47 struct _cat_msg_hdr
*r
;
50 if ((catd_st
== NULL
) || (catd_st
== (nl_catd
)-1)) {
51 /* invalid message catalog descriptor */
53 return ((char *)def_str
);
56 if ((catd_st
->__content
== NULL
) &&
57 (catd_st
->__size
== 0) && (catd_st
->__trust
== 1)) {
58 /* special message catalog descriptor for C locale */
59 return ((char *)def_str
);
60 } else if ((catd_st
->__content
== NULL
) || (catd_st
->__size
== 0)) {
61 /* invalid message catalog descriptor */
63 return ((char *)def_str
);
66 catd
= catd_st
->__content
;
67 p
= (struct _cat_hdr
*)catd_st
->__content
;
71 * Two while loops will perform binary search.
72 * Outer loop searches the set and inner loop searches
77 q
= (struct _cat_set_hdr
*)
80 + _CAT_SET_HDR_SIZE
* mid
);
81 if (q
->__set_no
== set_id
) {
82 lo
= q
->__first_msg_hdr
;
83 hi
= lo
+ q
->__nmsgs
- 1;
86 r
= (struct _cat_msg_hdr
*)
90 + _CAT_MSG_HDR_SIZE
* mid
);
91 if (r
->__msg_no
== msg_id
) {
92 char *msg
= (char *)catd
94 + p
->__msg_text_offset
97 if (!catd_st
->__trust
) {
98 int errno_save
= errno
;
99 char *cmsg
= check_format(
101 if (cmsg
== def_str
) {
112 } else if (r
->__msg_no
< msg_id
)
118 /* In case set number not found */
120 return ((char *)def_str
);
121 } else if (q
->__set_no
< set_id
)
127 /* In case msg_id not found. */
129 return ((char *)def_str
);