An installation may require that a global mechanism should be used for all C programs. The exit CEEBINT may be used for this purpose. Users can insert a setlocale() call inside the routines referencing the locale required. Figure 1 shows an example program (CCNGCL2).
/* this example refers implicitly to a customized locale */
#ifdef __cplusplus
extern "C"{
#else
#pragma linkage(CEEBINT,OS)
#endif
void CEEBINT(int, int, int, int, void**, int, void**);
#pragma map(CEEBINT,"CEEBINT")
#ifdef __cplusplus
}
#endif
#include <locale.h>
#include <stdio.h>
int main(void){
printf("Default NULL locale = %s\n", setlocale(LC_ALL,NULL));
printf("Default \"\" locale = %s\n", setlocale(LC_ALL,""));
}
void CEEBINT(int number, int retcode, int rsncode, int fnccode,
void **a_main, int userwd, void **a_exits)
{ /* user code goes here */
printf("CEEBINT entry. number = %i\n", number);
printf("Locale = %s\n", setlocale(LC_ALL,"Texan.IBM-1047"));
}
CEEBINT entry. number = 7
Locale = TEXAN.IBM-1047
Default NULL locale = TEXAN.IBM-1047
Default "" locale = S370
The exit CEEBINT may provide a uniform way of restricting the use of customized locales across an installation. To do this, a system programmer can compile CEEBINT separately, and link it with the application program that will use it. The disadvantage to this approach is that CEEBINT must be link-edited into each user module explicitly. See Using runtime user exits for more information about user exits.
Figure 2 shows a sample program (CCNGCL3) that uses environment variables to select a locale. (For more information about setting environment variables, see Using environment variables.)
/* this example can be used with setenv() to specify the name of a */
/* locale */
#include <locale.h>
#include <stdio.h>
int main(void){
printf("Default NULL locale = %s\n", setlocale(LC_ALL,NULL));
printf("Default \"\" locale = %s\n", setlocale(LC_ALL,""));
return(0);
}
Default NULL locale = C
Default "" locale = S370
Default NULL locale = C
Default "" locale = TEXAN.IBM-1047
In the example above, the default NULL locale returns C because the value of LC_ALL does not affect the current locale until the next setlocale(LC_ALL, "") is done. When this call is made, the LC_ALL environment variable will be used and the locale will be set to TEXAN.IBM-1047.
See z/OS XL C/C++ Runtime Library Reference for information about setlocale().