190181Sphantom/*-
290181Sphantom * Copyright (c) 2002 Alexey Zelkin <phantom@FreeBSD.org>
390181Sphantom * All rights reserved.
490181Sphantom *
590181Sphantom * Redistribution and use in source and binary forms, with or without
690181Sphantom * modification, are permitted provided that the following conditions
790181Sphantom * are met:
890181Sphantom * 1. Redistributions of source code must retain the above copyright
990181Sphantom *    notice, this list of conditions and the following disclaimer.
1090181Sphantom * 2. Redistributions in binary form must reproduce the above copyright
1190181Sphantom *    notice, this list of conditions and the following disclaimer in the
1290181Sphantom *    documentation and/or other materials provided with the distribution.
1390181Sphantom *
1490181Sphantom * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1590181Sphantom * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1690181Sphantom * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1790181Sphantom * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1890181Sphantom * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1990181Sphantom * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2090181Sphantom * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2190181Sphantom * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2290181Sphantom * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2390181Sphantom * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2490181Sphantom * SUCH DAMAGE.
2590181Sphantom *
2690181Sphantom * $FreeBSD$
2790181Sphantom */
2890181Sphantom
2990181Sphantom#include <locale.h>
3090181Sphantom#include <stdio.h>
3190189Sphantom#include <stdlib.h>
3290181Sphantom
3390181Sphantom/*
3490189Sphantom * Try setlocale() for locale with given name.
3590181Sphantom */
3690181Sphantom
3790181Sphantomstruct locdef {
3890189Sphantom	int		catid;
3990189Sphantom	const char	*catname;
4090181Sphantom} locales[_LC_LAST] = {
4190181Sphantom	{ LC_ALL,	"LC_ALL" },
4290181Sphantom	{ LC_COLLATE,	"LC_COLLATE" },
4390181Sphantom	{ LC_CTYPE,	"LC_CTYPE" },
4490181Sphantom	{ LC_MONETARY,	"LC_MONETARY" },
4590181Sphantom	{ LC_NUMERIC,	"LC_NUMERIC" },
4690181Sphantom	{ LC_TIME,	"LC_TIME" },
4790181Sphantom	{ LC_MESSAGES,	"LC_MESSAGES" }
4890181Sphantom};
4990181Sphantom
5090181Sphantomint
5193223Srumain(int argc, char *argv[])
5293223Sru{
5390189Sphantom	int i, result;
5490189Sphantom	const char *localename;
5590181Sphantom
5690181Sphantom	if (argc != 2) {
5795258Sdes		(void)fprintf(stderr, "usage: localeck <locale_name>\n");
5890181Sphantom		exit(1);
5990181Sphantom	}
6090181Sphantom
6190181Sphantom	localename = argv[1];
6290181Sphantom	result = 0;
6390181Sphantom
6490181Sphantom	for (i = 0; i < _LC_LAST; i++) {
6590181Sphantom		if (setlocale(locales[i].catid, localename) == NULL) {
6690181Sphantom			printf("setlocale(%s, %s) failed\n", locales[i].catname,
6790189Sphantom			    localename);
6890181Sphantom			result++;
6990181Sphantom		}
7090181Sphantom	}
7190181Sphantom	return (result);
7290181Sphantom}
73