locale: exit 1 if unknown keyword was specified
PR: 241906 Submitted by: Akos Somfai <akos.somfai@gmail.com>
This commit is contained in:
parent
3132c3cb3a
commit
e13e14499c
@ -61,7 +61,7 @@ void list_locales(void);
|
|||||||
const char *lookup_localecat(int);
|
const char *lookup_localecat(int);
|
||||||
char *kwval_lconv(int);
|
char *kwval_lconv(int);
|
||||||
int kwval_lookup(const char *, char **, int *, int *, int *);
|
int kwval_lookup(const char *, char **, int *, int *, int *);
|
||||||
void showdetails(const char *);
|
int showdetails(const char *);
|
||||||
void showkeywordslist(char *substring);
|
void showkeywordslist(char *substring);
|
||||||
void showlocale(void);
|
void showlocale(void);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
@ -414,7 +414,8 @@ main(int argc, char *argv[])
|
|||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
while (argc > 0) {
|
while (argc > 0) {
|
||||||
showdetails(*argv);
|
if (showdetails(*argv) != 0)
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
argv++;
|
argv++;
|
||||||
argc--;
|
argc--;
|
||||||
}
|
}
|
||||||
@ -837,19 +838,16 @@ kwval_lookup(const char *kwname, char **kwval, int *cat, int *type, int *alloc)
|
|||||||
* Show details about requested keyword according to '-k' and/or '-c'
|
* Show details about requested keyword according to '-k' and/or '-c'
|
||||||
* command line options specified.
|
* command line options specified.
|
||||||
*/
|
*/
|
||||||
void
|
int
|
||||||
showdetails(const char *kw)
|
showdetails(const char *kw)
|
||||||
{
|
{
|
||||||
int type, cat, tmpval, alloc;
|
int type, cat, tmpval, alloc;
|
||||||
char *kwval;
|
char *kwval;
|
||||||
|
|
||||||
if (kwval_lookup(kw, &kwval, &cat, &type, &alloc) == 0) {
|
if (kwval_lookup(kw, &kwval, &cat, &type, &alloc) == 0) {
|
||||||
/*
|
/* Invalid keyword specified */
|
||||||
* invalid keyword specified.
|
|
||||||
* XXX: any actions?
|
|
||||||
*/
|
|
||||||
fprintf(stderr, "Unknown keyword: `%s'\n", kw);
|
fprintf(stderr, "Unknown keyword: `%s'\n", kw);
|
||||||
return;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prt_categories) {
|
if (prt_categories) {
|
||||||
@ -889,6 +887,8 @@ showdetails(const char *kw)
|
|||||||
|
|
||||||
if (alloc)
|
if (alloc)
|
||||||
free(kwval);
|
free(kwval);
|
||||||
|
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -160,8 +160,24 @@ no_flags_posix_body()
|
|||||||
noexpr
|
noexpr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atf_test_case k_flag_unknown_kw
|
||||||
|
k_flag_unknown_kw_head()
|
||||||
|
{
|
||||||
|
atf_set "descr" \
|
||||||
|
"Verify 'locale -k' exit status is '1' for unknown keywords"
|
||||||
|
}
|
||||||
|
k_flag_unknown_kw_body()
|
||||||
|
{
|
||||||
|
export LC_ALL="C"
|
||||||
|
|
||||||
|
# Hopefully the keyword will stay nonexistent
|
||||||
|
atf_check -s exit:1 -o empty -e ignore locale -k nonexistent
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
atf_init_test_cases()
|
atf_init_test_cases()
|
||||||
{
|
{
|
||||||
atf_add_test_case k_flag_posix
|
atf_add_test_case k_flag_posix
|
||||||
atf_add_test_case no_flags_posix
|
atf_add_test_case no_flags_posix
|
||||||
|
atf_add_test_case k_flag_unknown_kw
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user