HP OpenVMS Systems Documentation

Content starts here HP C

HP C
Run-Time Library Reference Manual for OpenVMS Systems


Previous Contents Index


setlocale

Selects the appropriate portion of the program's locale as specified by the category and locale arguments. You can use this function to change or query one category or the program's entire current locale.

Format

#include <locale.h>

char *setlocale (int category, const char *locale);


Arguments

category

The name of the category. Specify LC_ALL to change or query the entire locale. Other valid category names are:
  • LC_COLLATE
  • LC_CTYPE
  • LC_MESSAGES
  • LC_MONETARY
  • LC_NUMERIC
  • LC_TIME

locale

Pointer to a string that specifies the locale.

Description

The setlocale function sets or queries the appropriate portion of the program's locale as specified by the category and locale arguments. Specifying LC_ALL for the category argument names the entire locale; specifying the other values name only a portion of the program's locale.

The locale argument points to a character string that identifies the locale to be used. This argument can be one of the following:

  • Name of the public locale
    Specifies the public locale in the following format:


    language_country.codeset[@modifier]
    

    The function searches for the public locale binary file in the location defined by the logical name SYS$I18N_LOCALE. The file type defaults to .LOCALE. The period (.) and at-sign (@) characters in the name are replaced by an underscore (_).
    For example, if the specified name is "zh_CN.dechanzi@radical", the function searches for the SYS$I18N_LOCALE:ZH_CN_DECHANZI_RADICAL.LOCALE binary locale file.
  • A file specification
    Specifies the binary locale file. It can be any valid file specification. If either the device or directory is omitted, the function first applies the current caller's device and directory as defaults for any missing component. If the file is not found, the function applies the device and directory defined by the SYS$I18N_LOCALE logical name as defaults. The file type defaults to .LOCALE.
    No wildcards are allowed. The binary locale file cannot reside on a remote node.
  • "C"
    Specifies the C locale. If a program does not call setlocale , the C locale is the default.
  • "POSIX"
    This is the same as the C locale.
  • ""
    Specifies that the locale is initialized from the setting of the international environment logical names. The function checks the following logical names in the order shown until it finds a logical that is defined:
    1. LC_ALL
    2. Logical names corresponding to the category. For example, if LC_NUMERIC is specified as the category, then the first logical name that setlocale checks is LC_NUMERIC.
    3. LANG
    4. SYS$LC_ALL
    5. The system default for the category, which is defined by the SYS$LC_* logical names. For example, the default for the LC_NUMERIC category is defined by the SYS$LC_NUMERIC logical name.
    6. SYS$LANG
      If none of the logical names is defined, the C locale is used as the default. The SYS$LC_* logical names are set up at the system startup time.

    Like the locale argument, the equivalence name of the international environment logical name can be either the name of the public locale or the file specification. The setlocale function treats this equivalence name as if it were specified as the locale argument.
  • NULL
    Causes setlocale to query the current locale. The function returns a pointer to a string describing the portion of the program's locale associated with category. Specifying the LC_ALL category returns the string describing the entire locale. The locale is not changed.
  • The string returned from the previous call to setlocale
    Causes the function to restore the portion of the program's locale associated with category. If the string contains the description of the entire locale, the part of the string corresponding to category is used. If the string describes the portion of the program's locale for a single category, this locale is used. For example, this means that you can use the string returned from the call setlocale with the LC_COLLATE category to set the same locale for the LC_MESSAGES category.
    If the specified locale is available, then setlocale returns a pointer to the string that describes the portion of the program's locale associated with category. For the LC_ALL category, the returned string describes the entire program's locale. If an error occurs, a NULL pointer is returned and the program's locale is not changed.
    Subsequent calls to setlocale overwrite the returned string. If that part of the locale needs to be restored, the program should save the string. The calling program should make no assumptions about the format or length of the returned string.

Return Values

x Pointer to a string describing the locale.
NULL Indicates an error occurred; errno is set.

Example


#include <errno.h>
#include <stdio.h>
#include <locale.h>

/* This program calls setlocale() three times. The second call  */
/* is for a nonexistent locale. The third call is for an        */
/* existing file that is not a locale file.                     */

main()
{
    char *ret_str;

    errno = 0;
    printf("setlocale (LC_ALL, \"POSIX\")");
    ret_str = (char *) setlocale(LC_ALL, "POSIX");

    if (ret_str == NULL)
        perror("setlocale error");
    else
        printf(" call was successful\n");

    errno = 0;
    printf("\n\nsetlocale (LC_ALL, \"junk.junk_codeset\")");
    ret_str = (char *) setlocale(LC_ALL, "junk.junk_codeset");

    if (ret_str == NULL)
        perror(" returned error");
    else
        printf(" call was successful\n");

    errno = 0;
    printf("\n\nsetlocale (LC_ALL, \"sys$login:login.com\")");
    ret_str = (char *) setlocale(LC_ALL, "sys$login:login.com");

    if (ret_str == NULL)
        perror(" returned error");
    else
        printf(" call was successful\n");
}

Running the example program produces the following result:


setlocale (LC_ALL, "POSIX") call was successful

setlocale (LC_ALL, "junk.junk_codeset")
returned error: no such file or directory

setlocale (LC_ALL, "sys$login:login.com")
returned error: nontranslatable vms error code: 0x35C07C
%c-f-localebad, not a locale file

setpgid (ALPHA ONLY)

Sets the process group ID for job control.

Format

#include <unistd.h>

int setpgid (pid_t pid, pid_t pgid);


Arguments

pid

The process ID for which the process group ID is to be set.

pgid

The value to which the process group ID is set.

Description

The setpgid function is used either to join an existing process group or create a new process group within the session of the calling process. The process group ID of a session leader will not change.

Upon successful completion, the process group ID of the process with a process ID of pid is set to pgid. As a special case, if pid is 0, the process ID of the calling process is used. Also, if pgid is 0, the process group ID of the indicated process is used.


Return Values

0 Successful completion.
- 1 Indicates an error. The function sets errno to one of the following values:
  • EACCES -- The value of the pid argument matches the process ID of a child process of the calling process and the child process has successfully executed one of the exec functions.
  • EINVAL -- The value of the pgid argument is less than 0, or is not a value supported by the implementation.
  • EPERM -- The process indicated by the pid argument is a session leader. The value of the pid argument matches the process ID of a child process of the calling process, and the child process is not in the same session as the calling process. The value of the pgid argument is valid but does not match the process ID of the process indicated by the pid argument, and there is no process with a process group ID that matches the value of the pgid argument in the same session as the calling process.
  • ESRCH -- The value of the pid argument does not match the process ID of the calling process or of a child process of the calling process.

setpgrp (ALPHA ONLY)

Sets the process group ID.

Format

#include <unistd.h>

pid_t setpgrp (void);


Description

If the calling process is not already a session leader, setpgrp sets the process group ID of the calling process to the process ID of the calling process. If setpgrp creates a new session, then the new session has no controlling terminal.

The setpgrp function has no effect when the calling process is a session leader.


Return Value

x The process group ID of the calling process.

setpwent

Rewinds the user database.

Format

#include <pwd.h>

void setpwent (void);


Description

The setpwent function effectively rewinds the user database to allow repeated searches.

No value is returned, but errno is set to EIO if an I/O error occurred.

See also getpwent .


setregid (ALPHA ONLY)

Sets the real and effective group IDs.

Format

#include <unistd.h>

int setregid (gid_t rgid, gid_t egid);


Arguments

rgid

The value to which you want the real group ID set.

egid

The value to which you want the effective group ID set.

Description

The setregid function is used to set the real and effective group IDs of the calling process. If rgid is - 1, the real group ID is not changed; if egid is - 1, the effective group ID is not changed. The real and effective group IDs can be set to different values in the same call.

Only a process with the IMPERSONATE privilege can set the real group ID and the effective group ID to any valid value.

A nonprivileged process can set either the real group ID to the saved set-group-ID from an exec function, or the effective group ID to the saved set-group-ID or the real group ID.

Any supplementary group IDs of the calling process remain unchanged.

If a set-group-ID process sets its effective group ID to its real group ID, it can still set its effective group ID back to the saved set-group-ID.


Return Values

0 Successful completion.
- 1 Indicates an error. Neither of the group IDs is changed, and errno is set to one of the following values:
  • EINVAL -- The value of the rgid or egid argument is invalid or out-of-range.
  • EPERM -- The process does not have the IMPERSONATE privilege, and a change other than changing the real group ID to the saved set-group-ID, or changing the effective group ID to the real group ID or the saved group ID, was requested.

setreuid (ALPHA ONLY)

Sets the user IDs.

Format

#include <unistd.h>

int setreuid (uid_t ruid, uid_t euid);


Arguments

ruid

The value to which you want the real user ID set.

euid

The value to which you want the effective user ID set.

Description

The setreuid function sets the real and effective user IDs of the current process to the values specified by the ruid and euid arguments. If ruid or euid is - 1, the corresponding effective or real user ID of the current process is left unchanged.

A process with the IMPERSONATE privilege can set either ID to any value. An unprivileged process can set the effective user ID only if the euid argument is equal to either the real, effective, or saved user ID of the process.

It is unspecified whether a process without the IMPERSONATE privilege is permitted to change the real user ID to match the current real, effective, or saved user ID of the process.


Return Values

0 Successful completion.
- 1 Indicates an error. The function sets errno to one of the following values:
  • EINVAL -- The value of the ruid or euid argument is invalid or out of range.
  • EPERM -- The current process does not have the IMPERSONATE privilege, and either an attempt was made to change the effective user ID to a value other than the real user ID or the saved set-user-ID, or an an attempt was made to change the real user ID to a value not permitted by the implementation.

setsid (ALPHA ONLY)

Creates a session and sets the process group ID.

Format

#include <unistd.h>

pid_t setsid (void);


Description

The setsid function creates a new session if the calling process is not a process group leader. Upon return, the calling process is the session leader of this new session and the process group leader of a new process group, and it has no controlling terminal. The process group ID of the calling process is set equal to the process ID of the calling process. The calling process is the only process in the new process group and the only process in the new session.

Return Values

x The process group ID of the calling process.
(pid_t) - 1 Indicates an error. The function sets errno to the following value:
  • EPERM -- The calling process is already a process group leader, or the process group ID of a process other than the calling process matches the process ID of the calling process.

setstate

Restarts and changes random-number generators.

Format

char *setstate (char *state;)


Argument

state

Points to the array of state information.

Description

The setstate function handles restarting and changing random-number generators.

Once you initialize a state, the setstate function allows rapid switching between state arrays. The array defined by state is used for further random-number generation until the initstate function is called or the setstate function is called again. The setstate function returns a pointer to the previous state array.

After initialization, you can restart a state array at a different point in one of two ways:

  • Use the initstate function, with the desired seed, state array, and size of the array.
  • Use the setstate function, with the desired state, followed by the srandom function with the desired seed . The advantage of using both functions is that you do not have to save the state array size once you initialize it.

See also initstate , srandom , and random .


Return Values

x A pointer to the previous state array information.
0 Indicates an error. The state information is damaged, and errno is set to the following value:
  • EINVAL---The state argument is invalid.

setuid

With POSIX IDs disabled, implemented for program portability and serves no function. It returns 0 (to indicate success).

With POSIX IDs enabled, sets the user IDs.


Format

#include <types.h>

#include <unistd.h>

int setuid (__uid_t uid); (_DECC_V4_SOURCE)

uid_t setuid (uid_t uid); (NOT _DECC_V4_SOURCE)


Argument

uid

The value to which you want the user IDs set.

Description

The setuid function can be used with POSIX style identifiers enabled or disabled.

POSIX style IDs are supported on OpenVMS Version 7.3-2 and higher.

With POSIX IDs disabled (the default), the setuid function is implemented for program portability and serves no function. It returns 0 (to indicate success).

With POSIX style IDs enabled:

  • If the process has the IMPERSONATE privilege, the setuid function sets the real user ID, effective user ID, and the saved set-user-ID to uid.
  • If the process does not have appropriate privileges but uid is equal to the real user ID or to the saved set-user-ID, then the setuid function sets the effective user ID to uid. The real user ID and saved set-user-ID remain unchanged.

To enable/disable POSIX style IDs, see Section 1.7.


Return Values

0 Successful completion.
- 1 Indicates an error. The function sets errno to one of the following values:
  • EINVAL -- The value of the uid argument is invalid and not supported by the implementation.
  • EPERM -- The process does not have appropriate privileges and uid does not match the real user ID or the saved set-user-ID.

setvbuf

Associates a buffer with an input or output file and potentially modifies the buffering behavior.

Format

#include <stdio.h>

int setvbuf (FILE *file_ptr, char *buffer, int type, size_t size);


Arguments

file_ptr

A pointer to a file.

buffer

A pointer to a character array, or a NULL pointer.

type

The buffering type. Use one of the following values defined in <stdio.h> : _IONBF, _IOFBF, or _IOLBF.

size

The number of bytes to be used in buffer by the HP C RTL for buffering this file. The buffer size must be a minimum of 8192 bytes and a maximum of 32767 bytes.

Description

You can use the setvbuf function after the file is opened but before any I/O operations are performed.

The ANSI C standard defines the following types of file buffering. In unbuffered I/O, each I/O operation is performed immediately. Output characters or lines are written to the output device before control is returned to the program. Input characters or lines are sent directly to the program without read-ahead by the HP C RTL.

In line-buffered I/O, characters are buffered in an area of memory until a new-line character is seen, at which point the appropriate RMS routine is called to transmit the entire buffer. Line buffering is more efficient than unbuffered I/O since it reduces the system overhead, but it delays the availability of the data to the user or disk on output.

In fully buffered I/O, characters are buffered in an area of memory until the buffer is full, regardless of the presence of break characters. Full buffering is more efficient than line buffering or unbuffered I/O, but it delays the availability of output data even longer than line buffering.

Use the values _IONBF, _IOLBF, and _IOFBF defined in <stdio.h> for the type argument to specify unbuffered, line-buffered, and fully buffered I/O, respectively.

If _IONBF is specified for type, I/O will be unbuffered and the buffer and size arguments are ignored.

If _IOLBF or _IOFBF is specified for type, the HP C RTL will use line-buffered I/O if file_ptr specifies a terminal device; otherwise, it will use fully buffered I/O.

The HP C RTL automatically allocates a buffer to use for each I/O stream, so there are several buffer allocation possibilities:

  • If buffer is not a NULL pointer and size is not smaller than the automatically allocated buffer, then setvbuf uses buffer as the file buffer.
  • If buffer is a NULL pointer or size is smaller than the automatically allocated buffer, the automatically allocated buffer is used as the buffer area.
  • If buffer is a NULL pointer and size is larger than the automatically allocated buffer, then setvbuf allocates a new buffer equal to the specified size and uses that as the file buffer.

User programs must not depend on the contents of buffer once I/O has been performed on the stream. The HP C RTL might or might not use buffer for any given I/O operation.

Generally, it is unnecessary to use setvbuf or setbuf to control the buffer size used by the HP C RTL. The automatically allocated buffer sizes are chosen for efficiency based on the kind of I/O operations performed and the device characteristics (such as terminal, disk, or socket).

The setvbuf and setbuf functions are useful to introduce buffering for improved performance when writing a large amount of text to the stdout stream. This stream is unbuffered by default when bound to a terminal device (the normal case), and therefore incurs a large number of OpenVMS buffered I/O operations unless HP C RTL buffering is introduced by a call to setvbuf or setbuf .

The setvbuf function is used only to control the buffering used by the HP C RTL, not the buffering used by the underlying RMS I/O operations. You can modify RMS default buffering behavior by specifying various values for the ctx, fop, rat, gbc, mbc, mbf, rfm, and rop RMS keywords when the file is opened by the creat , freopen or open functions.


Return Values

0 Indicates success.
nonzero value Indicates that an invalid input value was specifed for type or file_ptr, or because file_ptr is being used by another thread (see Section 1.9.1).


Previous Next Contents Index