Previous | Contents | Index |
Provides a way to transfer control from a nested series of function invocations back to a predefined point without returning normally. It does not use a series of return statements. The setjmp function saves the context of the calling function in an environment buffer.
#include <setjmp.h>int setjmp (jmp_buf env);
env
The environment buffer, which must be an array of integers long enough to hold the register context of the calling function. The type jmp_buf is defined in the <setjmp.h> header file. The contents of the general-purpose registers, including the program counter (PC), are stored in the buffer.
When setjmp is first called, it returns the value 0. If longjmp is then called, naming the same environment as the call to setjmp , control is returned to the setjmp call as if it had returned normally a second time. The return value of setjmp in this second return is the value supplied by you in the longjmp call. To preserve the true value of setjmp , the function calling setjmp must not be called again until the associated longjmp is called.The setjmp function preserves the hardware general-purpose registers, and the longjmp function restores them. After a longjmp , all variables have their values as of the time of the longjmp except for local automatic variables not marked volatile . These variables have indeterminate values.
The setjmp and longjmp functions rely on the OpenVMS condition-handling facility to effect a nonlocal goto with a signal handler. The longjmp function is implemented by generating a HP C RTL specified signal that allows the OpenVMS condition-handling facility to unwind back to the desired destination.
The HP C RTL must be in control of signal handling for any HP C image. For HP C to be in control of signal handling, you must establish all exception handlers through a call to the VAXC$ESTABLISH function. See Section 4.2.5 and the VAXC$ESTABLISH function for more information.
Note
The C RTL provides nonstandard decc$setjmp and decc$fast_longjmp functions for Alpha and I64 systems. To use these nonstandard functions instead of the standard ones, a program must be compiled with __FAST_SETJMP or __UNIX_SETJMP macros defined.
Unlike the standard longjmp function, the decc$fast_longjmp function does not convert its second argument from 0 to 1. After a call to decc$fast_longjmp , a corresponding setjmp function returns with the exact value of the second argument specified in the decc$fast_longjmp call.
You cannot invoke the longjmp function from an OpenVMS condition handler. However, you may invoke longjmp from a signal handler that has been established for any signal supported by the HP C RTL, subject to the following nesting restrictions:
- The longjmp function will not work if you invoke it from nested signal handlers. The result of the longjmp function, when invoked from a signal handler that has been entered as a result of an exception generated in another signal handler, is undefined.
- Do not invoke the setjmp function from a signal handler unless the associated longjmp is to be issued before the handling of that signal is completed.
- Do not invoke the longjmp function from within an exit handler (established with atexit or SYS$DCLEXH). Exit handlers are invoked after image tear-down, so the destination address of the longjmp no longer exists.
- Invoking longjmp from within a signal handler to return to the main thread of execution might leave your program in an inconsistent state. Possible side effects include the inability to perform I/O or to receive any more UNIX signals. Use siglongjmp instead.
See the Description section.
Sets an encoding key for use by the encrypt function.
#include <unistd.h>#include <stdlib.h>
void setkey (const char *key;)
key
A character array of length 64 containing 0s and 1s.
The argument of setkey is a character array of length 64 containing only the characters with numerical value 0 and 1. If this string is divided into groups of 8, the low-order bit in each group is ignored, leading to a 56-bit key which is set into the machine.No value is returned.
See also crypt and encrypt .
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.
#include <locale.h>char *setlocale (int category, const char *locale);
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.
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:
- LC_ALL
- 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.
- LANG
- SYS$LC_ALL
- 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.
- 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.
x Pointer to a string describing the locale. NULL Indicates an error occurred; errno is set.
#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
Sets the process group ID for job control.
#include <unistd.h>int setpgid (pid_t pid, pid_t pgid);
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.
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.
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.
Sets the process group ID.
#include <unistd.h>pid_t setpgrp (void);
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.
x The process group ID of the calling process.
Rewinds the user database.
#include <pwd.h>void setpwent (void);
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 .
Sets the real and effective group IDs.
#include <unistd.h>int setregid (gid_t rgid, gid_t egid);
rgid
The value to which you want the real group ID set.egid
The value to which you want the effective group ID set.
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.
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.
Sets the user IDs.
#include <unistd.h>int setreuid (uid_t ruid, uid_t euid);
ruid
The value to which you want the real user ID set.euid
The value to which you want the effective user ID set.
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.
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.
Creates a session and sets the process group ID.
#include <unistd.h>pid_t setsid (void);
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.The __USE_LONG_GID_T feature macro must be enabled to make the setsid function prototype visible.
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.
Restarts and changes random-number generators.
char *setstate (char *state;)
state
Points to the array of state information.
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 .
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.
Previous | Next | Contents | Index |