Software Internationalization Guide
The HP Internationalization Subsystem
Software Internationalization Guide—526225-002
4-9
Locales in OSS Client/Server Applications
Locales in OSS Client/Server Applications
For homogeneous client/server applications in the OSS environment, HP provides the
setlocale_from_msg() function to enable a server to receive a client's locale
information along with messages from $RECEIVE.
If a client that is not internationalized communicates with an internationalized server,
the only locale available is the C/POSIX default locale. If an internationalized client
communicates with a server that is not internationalized, the result is undefined.
To change a server's locale to match the locale associated with a client's message, the
server must specify that it wants to receive locale information:
•
Use FILE_OPEN_ option <13> (Locale Support) when opening $RECEIVE. This
option specifies that data messages are to have locale information sent with them,
and enables setlocale_from_msg() to adopt the locale of a client. After doing
a READUPDATE[X] operation on the $RECEIVE file, the server can adopt the
locale of a client from information sent with a write or writeread message from the
client.
•
When the server processes a client's request, call setlocale_from_msg() to
change the server locale to match that of the client before executing any other
locale-sensitive function.
See the setlocale_from_msg(3) reference page or the Open System Services
Library Calls Reference Manual for more information.
Example: Changing a Server Locale to Match the Client
Locale
The following example sets and saves the existing locale environment, then sets the
locale based on the received message, performs some operations in that locale, and
restores the locale to the saved environment. A program typically uses setlocale()
to set its locale environment to the locale specified by the user's environment variables
and uses setlocale_from_msg() to set the locale to match that of the client.
#include <locale.h>
#include <string.h>
#include <cextdecs.h>
void Do_setlocale_from_message(void)
{
char *client_lc, *server_lc;
short rf_num, options, read_cnt, fn_len;
char r_buf[80], receive_info[17];
/* Setting the locale from the environment variable LC_ALL. */
server_lc = setlocale(LC_ALL,"");
options = 4U; /* set bit-13 on so that locale
information can be received. */
FILE_OPEN_("$RECEIVE", 8, &rf_num,,,1, options);