14297a3b0SGarrett D'Amore /*
2*62c3776aSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org>
36b5e5868SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
44297a3b0SGarrett D'Amore * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
54297a3b0SGarrett D'Amore * All rights reserved.
64297a3b0SGarrett D'Amore *
74297a3b0SGarrett D'Amore * Redistribution and use in source and binary forms, with or without
84297a3b0SGarrett D'Amore * modification, are permitted provided that the following conditions
94297a3b0SGarrett D'Amore * are met:
104297a3b0SGarrett D'Amore * 1. Redistributions of source code must retain the above copyright
114297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer.
124297a3b0SGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
134297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer in the
144297a3b0SGarrett D'Amore * documentation and/or other materials provided with the distribution.
154297a3b0SGarrett D'Amore *
164297a3b0SGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174297a3b0SGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184297a3b0SGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194297a3b0SGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
204297a3b0SGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214297a3b0SGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224297a3b0SGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234297a3b0SGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244297a3b0SGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254297a3b0SGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264297a3b0SGarrett D'Amore * SUCH DAMAGE.
274297a3b0SGarrett D'Amore */
284297a3b0SGarrett D'Amore
294297a3b0SGarrett D'Amore #include "lint.h"
304297a3b0SGarrett D'Amore #include <stddef.h>
31*62c3776aSGarrett D'Amore #include <errno.h>
324297a3b0SGarrett D'Amore #include "ldpart.h"
334297a3b0SGarrett D'Amore #include "lmessages.h"
34*62c3776aSGarrett D'Amore #include "localeimpl.h"
354297a3b0SGarrett D'Amore
36*62c3776aSGarrett D'Amore #define LCMESSAGES_SIZE_FULL (sizeof (struct lc_messages) / sizeof (char *))
374297a3b0SGarrett D'Amore #define LCMESSAGES_SIZE_MIN \
38*62c3776aSGarrett D'Amore (offsetof(struct lc_messages, yesstr) / sizeof (char *))
394297a3b0SGarrett D'Amore
404297a3b0SGarrett D'Amore static char empty[] = "";
414297a3b0SGarrett D'Amore
42*62c3776aSGarrett D'Amore struct lc_messages lc_messages_posix = {
434297a3b0SGarrett D'Amore "^[yY]", /* yesexpr */
444297a3b0SGarrett D'Amore "^[nN]", /* noexpr */
454297a3b0SGarrett D'Amore "yes", /* yesstr */
464297a3b0SGarrett D'Amore "no" /* nostr */
474297a3b0SGarrett D'Amore };
484297a3b0SGarrett D'Amore
49*62c3776aSGarrett D'Amore struct locdata __posix_messages_locdata = {
50*62c3776aSGarrett D'Amore .l_lname = "C",
51*62c3776aSGarrett D'Amore .l_data = { &lc_messages_posix }
52*62c3776aSGarrett D'Amore };
534297a3b0SGarrett D'Amore
54*62c3776aSGarrett D'Amore struct locdata *
__lc_messages_load(const char * name)55*62c3776aSGarrett D'Amore __lc_messages_load(const char *name)
564297a3b0SGarrett D'Amore {
57*62c3776aSGarrett D'Amore struct locdata *ldata;
58*62c3776aSGarrett D'Amore struct lc_messages *lmsgs;
594297a3b0SGarrett D'Amore int ret;
604297a3b0SGarrett D'Amore
61*62c3776aSGarrett D'Amore if ((ldata = __locdata_alloc(name, sizeof (*lmsgs))) == NULL)
62*62c3776aSGarrett D'Amore return (NULL);
63*62c3776aSGarrett D'Amore lmsgs = ldata->l_data[0];
64*62c3776aSGarrett D'Amore
65*62c3776aSGarrett D'Amore ret = __part_load_locale(name, (char **)&ldata->l_data[1],
66*62c3776aSGarrett D'Amore "LC_MESSAGES", LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
67*62c3776aSGarrett D'Amore (const char **)lmsgs);
68*62c3776aSGarrett D'Amore
69*62c3776aSGarrett D'Amore if (ret != _LDP_LOADED) {
70*62c3776aSGarrett D'Amore __locdata_free(ldata);
71*62c3776aSGarrett D'Amore errno = EINVAL;
72*62c3776aSGarrett D'Amore return (NULL);
734297a3b0SGarrett D'Amore }
744297a3b0SGarrett D'Amore
75*62c3776aSGarrett D'Amore if (lmsgs->yesstr == NULL)
76*62c3776aSGarrett D'Amore lmsgs->yesstr = empty;
77*62c3776aSGarrett D'Amore if (lmsgs->nostr == NULL)
78*62c3776aSGarrett D'Amore lmsgs->nostr = empty;
79*62c3776aSGarrett D'Amore
80*62c3776aSGarrett D'Amore return (ldata);
814297a3b0SGarrett D'Amore }
82