Referring implicitly to a customized locale

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).

Figure 1. Referring implicitly to a customized locale
/* 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"));
   }
If the above example is compiled and executed with the TEXAN locale, the results are as follows:
     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.)

Figure 2. Using environment variables to select a locale
/* 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);
 }
If you run this program in Figure 2 as is, without calling setenv(), you can expect the following result (for a 31-bit, POSIX(OFF), program ):
Default NULL locale = C
Default "" locale = S370
On the other hand, if you issue the above setenv() call after main() but before the first printf() statement, the LC_ALL variable will be set to "TEXAN.IBM-1047" and you can expect this result instead:
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.

The names of the environment variables match the names of the locale categories:

See z/OS XL C/C++ Runtime Library Reference for information about setlocale().