The C library provides much of the power usually associated with the C language. This chapter introduces the individual functions (and macros) that comprise the Watcom C library for QNX 4. The Library Functions and Macros chapter describes each function and macro in detail.
Library functions are called as if they had been defined within the program. When the program is linked, the code for these routines is incorporated into the program by the linker.
Strictly speaking, it isn't necessary to declare the library functions that return int. However, it's best to declare all functions by including the header files found in the Synopsis section with each function. Not only does this declare the return value, but also the type expected for each of the arguments as well as the number of arguments. This enables the Watcom C and C++ compilers to check the arguments coded with each function call.
This chapter includes the following:
The functions in the Watcom C library can be organized into a number of classes:
The following subsections describe these function classes in more detail. Each function in the class is noted with a brief description of its purpose. The chapter Library Functions and Macros provides a complete description of each function and macro.
These functions operate upon single characters of type char. The functions test characters in various ways and convert them between upper and lowercase.
Function | Summary |
---|---|
isalnum() | test for a letter or digit |
isalpha() | test for a letter |
isascii() | test for an ASCII character |
iscntrl() | test for a control character |
__iscsym() | test for a letter, underscore or digit |
__iscsymf() | test for a letter or underscore |
isdigit() | test for a digit |
isgraph() | test for a printable character, except a space |
islower() | test for a letter in lowercase |
isprint() | test for a printable character, including a space |
ispunct() | test for punctuation characters |
isspace() | test for “white space” characters |
isupper() | test for a letter in uppercase |
isxdigit() | test for a hexadecimal digit |
tolower() | convert a character to lowercase |
toupper() | convert a character to uppercase |
These functions manipulate blocks of memory. In each case, the address of the memory block and its size is passed to the function. The functions that begin with _f accept far pointers as their arguments, allowing manipulation of any memory location, regardless of which memory model your program has been compiled for.
Function | Summary |
---|---|
_fmemccpy() | copy a far memory block up to a certain character |
_fmemchr() | search a far memory block for a character value |
_fmemcmp() | compare any two memory blocks (near or far) |
_fmemcpy() | copy a far memory block, overlap not allowed |
_fmemicmp() | compare far memory, case insensitive |
_fmemmove() | copy a far memory block, overlap allowed |
_fmemset() | set any memory block (near or far) to a character |
memccpy() | copy a memory block up to a certain character |
memchr() | search a memory block for a character value |
memcmp() | compare memory blocks |
memcpy() | copy a memory block, overlap not allowed |
memicmp() | compare memory, case insensitive |
memmove() | copy a memory block, overlap allowed |
memset() | set a memory block to a character |
movedata() | copy a memory block, with segment information |
swab() | swap bytes of a memory block |
See the section “String Manipulation Functions” for descriptions of functions that manipulate strings of data.
A string is an array of characters (with type char) that is terminated with an extra null character ('\0'). Functions are passed only the address of the string, since the size can be determined by searching for the terminating character. The functions that begin with _f accept far pointers as their arguments, allowing manipulation of any memory location, regardless of which memory model your program has been compiled for.
Function | Summary |
---|---|
_bprintf() | formatted transmission to a fixed-length string |
_cmdname() | get the executing program's pathname |
_fstrcat() | concatenate two far strings |
_fstrchr() | locate a character in a far string |
_fstrcmp() | compare two far strings |
_fstrcpy() | copy a far string |
_fstrcspn() | get the number of string characters not from a set of characters |
_fstrdup() | allocate and duplicate a string |
_fstricmp() | compare two far strings with case insensitivity |
_fstrlen() | compute the length of a far string |
_fstrlwr() | convert a far string to lowercase |
_fstrncat() | concatenate two far strings, up to a maximum length |
_fstrncmp() | compare two far strings up to maximum length |
_fstrncpy() | copy a far string, up to a maximum length |
_fstrnicmp() | compare two far strings with case insensitivity, up to a maximum length |
_fstrnset() | fill a far string with a character, to a maximum length |
_fstrpbrk() | locate an occurrence of a string within a second string |
_fstrrchr() | locate the last occurrence of a character from a character set |
_fstrrev() | reverse a far string in place |
_fstrset() | fill a far string with a character |
_fstrspn() | find the number of characters at the start of a string that are also in a second string |
_fstrstr() | find the first occurrence of a string in a second string |
_fstrtok() | get the next token from a far string |
_fstrupr() | convert a far string to uppercase |
sprintf() | formatted transmission to a string |
sscanf() | scan from a string, under format control |
strcat() | concatenate two strings |
strchr() | locate a character in a string |
strcmp() | compare two strings |
strcmpi() | compare two strings, with case insensitivity |
strcoll() | compare two strings using the locale's collating sequence |
strcpy() | copy a string |
strcspn() | get the number of string characters not from a set of characters |
strdup() | allocate and duplicate a string |
strerror() | get an error message as a string |
stricmp() | compare two strings, with case insensitivity |
strlen() | compute the length of a string |
strlwr() | convert a string to lowercase |
strncat() | concatenate two strings, up to a maximum length |
strncmp() | compare two strings, up to maximum length |
strncpy() | copy a string, up to a maximum length |
strnicmp() | compare two strings, with case insensitivity, up to a maximum length |
strnset() | fill a string with a character, to a maximum length |
strpbrk() | locate an occurrence of a string within a second string |
strrchr() | locate the last occurrence of a character from a character set |
strrev() | reverse a string in place |
strset() | fill a string with a character |
strspn() | find the number of characters at the start of a string that are also in a second string |
strstr() | find the first occurrence of a string in a second string |
strtok() | get the next token from a string |
strupr() | convert a string to uppercase |
strxfrm() | transform a string to the locale's collating sequence |
_vbprintf() | same as _bprintf(), but with variable arguments |
vsprintf() | same as sprintf(), but with variable arguments |
vsscanf() | same as sscanf(), but with variable arguments |
For related functions see the sections:
These ANSI C functions provide capabilities for processing multibyte characters.
Function | Summary |
---|---|
mblen() | determine the length of the next multibyte character |
mbstowcs() | convert a multibyte character string to a wide character string |
mbtowc() | convert a multibyte character to a wide character |
wcstombs() | convert a wide character string to a multibyte character string |
wctomb() | convert a wide character to a multibyte character |
These functions perform conversions between objects of various types and strings.
Function | Summary |
---|---|
atof() | string to double |
atoh() | hexadecimal string to unsigned int |
atoi() | string to int |
atol() | string to long int |
ecvt() | double to E-format string |
fcvt() | double to F-format string |
gcvt() | double to string |
itoa() | int to string |
ltoa() | long int to string |
_strdate() | copy the current date into a buffer |
_strtime() | copy the current time into a buffer |
strtod() | string to double |
strtol() | string to long int |
strtoul() | string to unsigned long int |
ultoa() | unsigned long int to string |
utoa() | unsigned int to string |
See also the following functions, which convert the cases of characters and strings:
These functions allocate and de-allocate blocks of memory.
The default data segment has a maximum size of 64K bytes. It may be less in a machine with insufficient memory, or when other programs in the computer already occupy some of the memory. The _nmalloc() function allocates space within this area, while the _fmalloc() function allocates space outside the area (if it's available).
In a small data model, the malloc(), calloc() and realloc() functions use the _nmalloc() function to acquire memory; in a large data model, the _fmalloc() function is used.
It is also possible to allocate memory from a based heap using _bmalloc(). Based heaps are similar to far heaps in that they are located outside the normal data segment. Based pointers only store the offset portion of the full address, so they behave much like near pointers. The selector portion of the full address specifies which based heap a based pointer belongs to, and must be passed to the various based heap functions.
It is important to use the appropriate memory-deallocation function to free memory blocks:
The free() function uses the _nfree() function when the small data memory model is used; it uses the _ffree() function when the large data memory model is used.
The following functions are defined:
Function | Summary |
---|---|
alloca() | allocate automatic storage from stack |
_bcalloc() | allocate and zero memory from a based heap |
_bexpand() | expand a block of memory in a based heap |
_bfree() | free a block of memory in a based heap |
_bfreeseg() | free a based heap |
_bheapseg() | allocate a based heap |
_bmalloc() | allocate a memory block from a based heap |
_bmsize() | return the size of a memory block |
_brealloc() | reallocate a memory block in a based heap |
calloc() | allocate and zero memory |
_expand() | expand a block of memory |
_fcalloc() | allocate and zero a memory block (outside the default data segment) |
_fexpand() | expand a block of memory (outside the default data segment) |
_ffree() | free a block allocated using _fmalloc() |
_fmalloc() | allocate a memory block (outside the default data segment) |
_fmsize() | return the size of a memory block |
_frealloc() | reallocate a memory block (outside default data segment) |
free() | free a block allocated using malloc(), calloc() or realloc() |
_freect() | return the number of objects that can be allocated |
halloc() | allocate a huge array |
hfree() | free a huge array |
malloc() | allocate a memory block (using the current memory model) |
_memavl() | return the amount of available memory |
_memmax() | return the sixe of the largest block of memory available |
_msize() | return the size of a memory block |
_ncalloc() | allocate and zero a memory block (inside the default data segment) |
_nexpand() | expand a block of memory (inside the default data segment) |
_nfree() | free a block allocated using _nmalloc() |
_nmalloc() | allocate a memory block (inside the default data segment) |
_nmsize() | return the size of a memory block |
_nrealloc() | reallocate a memory block (inside the default data segment) |
realloc() | reallocate a block of memory |
sbrk() | set the allocation “break” position |
set_new_handler() | set the error handler for the new operator |
_set_new_handler() | set the error handler for the new operator |
stackavail() | determine the available amount of stack space |
These functions provide the ability to shrink and grow the heap, as well as find heap-related problems.
Function | Summary |
---|---|
_heapchk() | perform a consistency check on the heap |
_bheapchk() | perform a consistency check on a based heap |
_fheapchk() | perform a consistency check on the far heap |
_nheapchk() | perform a consistency check on the near heap |
_heapenable() | control attempts to grow the heap |
_heapgrow() | grow the heap |
_fheapgrow() | grow the far heap |
_nheapgrow() | grow the near heap up to its limit of 64K |
_heapmin() | shrink the heap as much as possible |
_bheapmin() | shrink a based heap as much as possible |
_fheapmin() | shrink the far heap as much as possible |
_nheapmin() | shrink the near heap as much as possible |
_heapset() | fill the unallocated sections of heap with a pattern |
_bheapset() | fill the unallocated sections of based heap with a pattern |
_fheapset() | fill the unallocated sections of far heap with a pattern |
_nheapset() | fill the unallocated sections of near heap with a pattern |
_heapshrink() | shrink the heap as much as possible |
_fheapshrink() | shrink the far heap as much as possible |
_bheapshrink() | shrink a based heap as much as possible |
_nheapshrink() | shrink the near heap as much as possible |
_heapwalk() | walk through each entry in the heap |
_bheapwalk() | walk through each entry in a based heap |
_fheapwalk() | walk through each entry in the far heap |
_nheapwalk() | walk through each entry in the near heap |
These functions operate with objects of type double, also known as floating-point numbers. The Intel 8087 processor (and its successor chips) is commonly used to implement floating-point operations on personal computers. Functions ending in “87” pertain to this specific hardware, and should be isolated in programs when portability is a consideration.
Function | Summary |
---|---|
abs() | absolute value of an object of type int |
acos() | arccosine |
acosh() | inverse hyperbolic cosine |
asin() | arcsine |
asinh() | inverse hyperbolic sine |
atan() | arctangent of one argument |
atan2() | arctangent of two arguments |
atanh() | inverse hyperbolic tangent |
Bessel Functions | Bessel functions j0(), j1(), jn(), y0(), y1(), and yn() |
cabs() | absolute value of a complex number |
ceil() | ceiling function |
_clear87() | clears floating-point status |
_control87() | sets new floating-point control word |
cos() | cosine |
cosh() | hyperbolic cosine |
div() | compute quotient and remainder from division of an int object |
exp() | exponential function |
fabs() | absolute value of double |
floor() | floor function |
fmod() | modulus function |
_fpreset() | initialize for floating-point operations |
frexp() | fractional exponent |
hypot() | compute hypotenuse |
j0() | return Bessel functions of the first kind (described under “Bessel Functions”) |
j1() | return Bessel functions of the first kind (described under “Bessel Functions”) |
jn() | return Bessel functions of the first kind (described under “Bessel Functions”) |
labs() | absolute value of an object of type long int |
ldexp() | multiply by a power of two |
ldiv() | get quotient and remainder from division of object of type long int |
log() | natural logarithm |
log10() | logarithm, base 10 |
log2() | logarithm, base 2 |
matherr() | handle errors from math functions |
max() | return the maximum of two arguments |
min() | return the minimum of two arguments |
modf() | get the integral and fractional parts of a double |
pow() | raise to power |
rand() | random integer |
sin() | sine |
sinh() | hyperbolic sine |
sqrt() | square root |
srand() | set starting point for generation of random numbers using rand() function |
_status87() | get the floating-point status |
tan() | tangent |
tanh() | hyperbolic tangent |
y0() | return Bessel functions of the second kind (described under “Bessel Functions”) |
y1() | return Bessel functions of the second kind (described under “Bessel Functions”) |
yn() | return Bessel functions of the second kind (described under “Bessel Functions”) |
These functions provide searching and sorting capabilities:
Function | Summary |
---|---|
bsearch() | find a data item in an array using a binary search |
_fstrcspn() | get the number of string characters not from a given set of characters |
_fstrstr() | find one far string inside another |
lfind() | find a data item in an array using a linear search |
lsearch() | find a data item in an array using a linear search, adding the item if it isn't found |
qsort() | sort an array |
These functions are concerned with dates and times.
Function | Summary |
---|---|
_asctime() | make a time string from a time structure |
asctime() | make a time string from a time structure |
clock() | get the time since the program started |
_ctime() | get the calendar time string |
ctime() | get the calendar time string |
difftime() | calculate the difference between two times |
ftime() | return the current time in a timeb structure |
_gmtime() | convert calendar time to Coordinated Universal Time (UTC) |
gmtime() | convert calendar time to Coordinated Universal Time (UTC) |
_localtime() | convert calendar time to local time |
localtime() | convert calendar time to local time |
mktime() | make calendar time from local time |
_strdate() | format the date as MM/DD/YY |
strftime() | format the date and time |
_strtime() | format the time as HH:MM:SS |
time() | get the current calendar time |
tzset() | set global variables to reflect the local time zone |
Variable-length argument lists are used when a function doesn't have a fixed number of arguments. These macros provide the capability to access these arguments:
Function | Summary |
---|---|
va_arg() | get the next variable argument |
va_end() | finish accessing variable arguments |
va_start() | start accessing variable arguments |
A stream is the name given to a file or device that has been opened for data transmission. When a stream is opened, a pointer to a FILE structure is returned. This pointer is used to reference the stream when other functions are subsequently invoked.
When a program begins execution, there are a number of streams already open for use:
These standard streams may be re-directed by use of the freopen() function.
See also the section “File Manipulation Functions” for other functions that operate upon files.
The functions referenced in the section “Operating System I/O Functions” may also be invoked (use the fileno() function to obtain the file descriptor). Since the stream functions may buffer input and output, these functions should be used with caution to avoid unexpected results.
Function | Summary |
---|---|
clearerr() | clear the end-of-file and error indicators for stream |
fclose() | close a stream |
fcloseall() | close all open streams |
fdopen() | open a stream, given a descriptor |
feof() | test for the end of a file |
ferror() | test for a file error |
fflush() | flush an output buffer |
fgetc() | get the next character from file |
fgetchar() | equivalent to fgetc() with the argument stdin |
fgetpos() | get the current file position |
fgets() | get a string |
flushall() | flush the output buffers for all streams |
fopen() | open a stream |
fprintf() | format output |
fputc() | write a character |
fputchar() | write a character to the stdout stream |
fputs() | write a string |
fread() | read a number of objects |
freopen() | re-open a stream |
fscanf() | scan input according to a format |
fseek() | set the current file position, relative |
fsetpos() | set the current file position, absolute |
_fsopen() | open a shared stream |
ftell() | get the current file position |
fwrite() | write a number of objects |
getc() | read a character |
getchar() | get the next character from stdin |
gets() | get a string from stdin |
perror() | write an error message to stderr stream |
printf() | format output to stdout |
putc() | write a character to a file |
putchar() | write a character to stdout |
puts() | write a string to stdout |
rewind() | position to the start of a file |
scanf() | scan input from stdin, under format control |
setbuf() | set a buffer |
setvbuf() | set buffering |
tmpfile() | create a temporary file |
ungetc() | push a character back on the input stream |
vfprintf() | same as fprintf(), but with variable arguments |
vfscanf() | same as fscanf(), but with variable arguments |
vprintf() | same as printf(), but with variable arguments |
vscanf() | same as scanf(), but with variable arguments |
See the section “Directory Functions” for functions that are related to directories.
These functions deal with process creation, execution and termination, signal handling, and timer operations.
When a new process is started, it replaces the existing process in the following cases:
The existing process may be suspended while the new process executes (control continues at the point following the place where the new process was started) in the following situations:
The following functions are defined:
Function | Summary |
---|---|
abort() | terminate a process immediately, return code 3 |
alarm() | send the calling process a SIGALRM signal after a specified time |
atexit() | register an exit routine |
_beginthread() | start a new thread of execution |
delay() | delay for a number of milliseconds |
_endthread() | end the current thread |
execl() | chain to a program |
execle() | chain to a program, pass the environment |
execlp() | chain to a program |
execlpe() | chain to a program, pass the environment |
execv() | chain to a program |
execve() | chain to a program, pass the environment |
execvp() | chain to a program |
execvpe() | chain to a program, pass the environment |
exit() | exit the process, set return code |
_exit() | exit the process, set return code |
fork() | create a new process |
kill() | send a signal to a specified process |
onexit() | register an exit routine |
pause() | suspend the calling process until signal |
raise() | signal an exceptional condition |
sigaction() | examine or specify action for a specific signal |
sigaddset() | add a specified signal to a set |
sigdelset() | delete a specified signal from a set |
sigemptyset() | initialize a signal set to exclude certain signals |
sigfillset() | initialize a signal set to include certain signals |
sigismember() | test whether or not a signal is a member of a set |
signal() | set the handling for an exceptional condition |
sigpending() | store a set of pending signals |
sigprocmask() | examine or change a process's signal mask |
sigsuspend() | replace a process's signal mask, and then suspend the process |
sleep() | delay for a number of seconds |
spawnl() | create a process |
spawnle() | create a process, set the environment |
spawnlp() | create a process |
spawnlpe() | create a process, set the environment |
spawnv() | create a process |
spawnve() | create a process, set the environment |
spawnvp() | create a process |
spawnvpe() | create a process, set the environment |
system() | execute a system command |
tfork() | create a new thread of execution |
wait() | wait for any child process to terminate |
waitpid() | wait for a child process to terminate |
There are eight spawn...() and exec...() functions each. The "..." is one to three letters:
These functions deal with process identification, user identification, process groups, system identification, system time and process time, environment variables, terminal identification, and configurable system variables.
The following functions are defined:
Function | Summary |
---|---|
_bgetcmd() | get the command line |
clearenv() | delete environment variables |
confstr() | get configuration-defined string values |
ctermid() | return the name of the controlling terminal |
cuserid() | generate the login name of the owner of the process |
getcmd() | get the command line |
getnid() | return a netword ID |
getpid() | return the process ID of the calling process |
getppid() | return the parent process ID of the calling process |
getegid() | return the effective group ID |
getenv() | get an environment variable value |
geteuid() | return the effective user ID |
getgid() | return the real group ID |
getgroups() | get supplementary group IDs |
getlogin() | return the user's login name |
getpgrp() | return the process group ID |
getsid() | return the session ID of a process |
getuid() | return the real user ID |
isatty() | determine if the file descriptor is associated with a terminal |
main() | the function where program execution begins |
putenv() | add, change or delete environment variables |
_searchenv() | search for a file in a list of directories |
searchenv() | search for a file in a list of directories |
setegid() | set the effective group ID |
setenv() | add, change or delete environment variables |
seteuid() | set the effective user ID |
setgid() | set the real group ID, effective group ID |
setpgid() | set the process group ID for job control |
setsid() | create a new session and set the process group ID |
setuid() | set the real user ID, the effective user ID |
sysconf() | determine the value of configurable system limit or option |
times() | return time-accounting information |
ttyname() | return a pointer to string containing the pathname of terminal associated with a file descriptor |
uname() | return operating system identification |
These functions pertain to directory manipulation:
Function | Summary |
---|---|
chdir() | change the current working directory |
closedir() | close an opened directory file |
getcwd() | get the current working directory |
mkdir() | make a new directory |
opendir() | open a directory file |
readdir() | read a file name from a directory |
rewinddir() | reset the position of a directory stream |
rmdir() | remove a directory |
These functions operate at the operating-system level, and are included for compatibility with other C implementations. It is recommended that the functions used in the section “File Manipulation Functions” be used for new programs, as these functions are defined portably, and are part of the ANSI standard for the C language.
The functions in this section reference opened files and devices using a file descriptor that's returned when the file is opened. The file descriptor is passed to the other functions.
The following functions are defined:
Function | Summary |
---|---|
chsize() | change the size of a file |
close() | close a file |
creat() | create a file |
dup() | duplicate a file descriptor, getting an unused descriptor number |
dup2() | duplicate a file descriptor, supplying a new descriptor number |
eof() | test for the end of a file |
fcntl() | control over an open file |
fdatasync() | write queued file data to disk |
filelength() | get file size |
fileno() | get a file descriptor for a stream file |
fstat() | get file status |
fsync() | write queued file and filesystem data to disk |
link() | create a new directory entry |
lock() | lock a section of a file |
locking() | lock/unlock a section of a file |
lseek() | set the current file position |
ltrunc() | truncate a file |
mkfifo() | make a FIFO special file |
mknod() | make a filesystem entry point |
mount() | mount a filesystem |
open() | open a file |
pclose() | close a pipe |
pipe() | create an inter-process channel |
popen() | open a pipe |
read() | read a record |
readlink() | read a symbolic link |
readv() | read several records, placing them into a specified number of buffers |
select() | synchronous I/O multiplexing |
setmode() | set file mode |
sopen() | open a file for shared access |
symlink() | create a symbolic link |
sync() | synchronize the filesystem |
tell() | get the current file position |
umask() | set the file permission mask |
umount() | unmount a filesystem |
unlink() | delete a file |
unlock() | unlock a section of a file |
write() | write a record |
writev() | write several records from a specified number of buffers |
These functions operate directly with files. The following functions are defined:
Function | Summary |
---|---|
access() | test a file or directory for mode of access |
chmod() | change the permissions for a file |
chown() | change the owner user ID and group ID of the specified file |
fchmod() | change the permissions for the file associated with the specified file descriptor to the specified mode |
fchown() | change the user ID and group ID of the file associated with the specified file descriptor to the specified numeric values |
fpathconf() | determine the value of a configurable limit associated with a file or directory |
lstat() | get file status |
pathconf() | determine the value of a configurable limit associated with a file or directory |
remove() | delete a file |
rename() | rename a file |
stat() | get file status |
tmpnam() | create a name for a temporary file |
unlink() | delete a file |
utime() | set the modification time for a file |
These functions provide the capability to read and write data from the console. Data is read or written without any special initialization (devices are not opened or closed), since the functions operate at the hardware level.
The following functions are defined:
Function | Summary |
---|---|
cgets() | get a string from the console |
cprintf() | print a formatted string to the console |
cputs() | write a string to the console |
cscanf() | scan formatted data from the console |
getch() | get a character from console, without echoing it |
getche() | get a character from console, echoing it |
kbhit() | test if a keystroke is available |
putch() | write a character to the console |
ungetch() | push back the next character from the console |
vcprintf() | write formatted output directly to the console |
vcscanf() | scan input from the console |
These functions deal with message queues:
Function | Summary |
---|---|
mq_close() | close a message queue |
mq_getattr() | get the current attributes of a message queue |
mq_notify() | notify the calling process when the queue becomes non-empty |
mq_open() | open a message queue |
mq_receive() | receive a message from a queue |
mq_send() | put a message into a message queue |
mq_setattr() | set the flags for a message queue |
mq_unlink() | delete a message queue |
These functions provide realtime timer capabilities:
Function | Summary |
---|---|
clock_getres() | get the resolution of a clock |
clock_gettime() | get the current time of a clock |
clock_setres() | set the resolution of a clock |
clock_settime() | set the current time of a clock |
nanosleep() | suspend a process until a timeout or signal |
sched_getparam() | get current scheduling parameters of a process |
sched_getscheduler() | get the current scheduling policy of a process |
sched_setparam() | set the scheduling parameters of a process |
sched_setscheduler() | set the priority and scheduling policy of a process |
sched_yield() | give up the processor to another process |
timer_create() | create a timer for current process |
timer_delete() | return a timer to the free list |
timer_gettime() | get the pending expiration time of a timer |
timer_settime() | set the expiration time of a timer |
These functions deal with semaphores:
Function | Summary |
---|---|
sem_destroy() | destroy a semaphore |
sem_init() | initialize a semaphore |
sem_post() | increment a semaphore |
sem_trywait() | wait on a semaphore, but don't block |
sem_wait() | wait on a semaphore |
These functions provide memory mapping capabilities:
Function | Summary |
---|---|
mmap() | map process addresses to a memory object |
mprotect() | change memory protection |
munmap() | unmap previously mapped addresses |
shm_open() | open a shared memory object |
shm_unlink() | remove a shared memory object |
The following functions are defined:
Function | Summary |
---|---|
cfgetispeed() | get the terminal input baud rate |
cfgetospeed() | get the terminal output baud rate |
cfsetispeed() | set the terminal input baud rate |
cfsetospeed() | set the terminal output baud rate |
tcdrain() | wait until all output is written |
tcdropline() | initiate a disconnect condition on the communication line associated with the specified opened file descriptor |
tcflow() | suspend the transmission or reception of data |
tcflush() | discard untransmitted data |
tcgetattr() | get terminal attributes |
tcgetpgrp() | return the value of process group ID of the foreground process group associated with the terminal |
tcsetattr() | set terminal attributes |
tcsetct() | make the terminal device, associated with the specified file descriptor, a controlling terminal that's associated with the specified process id |
tcsetpgrp() | set the foreground process group ID associated with the terminal |
tcsendbreak() | transmit a terminal “break” for a specified time |
The following functions are defined:
Function | Summary |
---|---|
endgrent() | close a group database |
endpwent() | close the list of system users |
getgrent() | get the next group entry |
getgrgid() | get the group information, based on a group ID |
getgrnam() | get the group information, based on a name |
getpwent() | peruse the list of system users |
getpwnam() | get password information, based on a name |
getpwuid() | get password information, based on a user ID |
setgrent() | rewind to the start of a group database |
setpwent() | rewind to the start of the list of system users |
The following functions are defined:
Function | Summary |
---|---|
basename() | return a pointer to the first character following the last “/” in a string |
block_read() | read a specified number of blocks of data from a file |
block_write() | write a specified number of blocks of data to a file |
console_active() | make the indicated console the “active” console |
console_arm() | trigger the specified proxy whenever one of the indicated console events occurs on the console |
console_close() | close a previously opened control channel to the device driver of a console device |
console_ctrl() | set bits in the console control word |
console_font() | change a console font |
console_info() | get console information |
console_open() | open up a control channel to the device driver of a console device |
console_protocol() | change a console's protocol emulation |
console_read() | read data directly from the video buffer of the indicated console |
console_size() | change and or report the size of the indicated console |
console_state() | test and set (or clear) the state of the current events that are pending on the indicated console device |
console_write() | write data directly to the video buffer of the indicated console |
Creceive() | check to see if a message is waiting from the process identified by the specified process ID |
Creceivemx() | check to see if a message is waiting from the process identified by the specified process ID |
dev_arm() | trigger the specified proxy whenever one of the indicated terminal device events occurs on the terminal device associated with the specified file descriptor |
dev_fdinfo() | return information about the terminal device that is controlled by the specified server process, and that is associated with the specified file descriptor belonging to the specified process |
dev_info() | return information about the terminal device associated with the specified file descriptor |
dev_insert_chars() | insert characters into the canonical input buffer of the opened device |
dev_ischars() | return the number of bytes available to be read from the terminal device associated with the specified file descriptor |
dev_mode() | test and optionally set (or clear) one of the input/output modes pertaining to the terminal device associated with specified file descriptor |
dev_read() | read up to n bytes of data from the specified terminal device into a buffer |
dev_state() | test and set (or clear) the state of the current events that are pending on the terminal device associated with the specified file descriptor |
disk_get_entry() | obtain information about the disk (both logical partition and physical disk) associated with the specified file descriptor |
disk_space() | obtain information about the size of the disk associated with the specified file descriptor |
errno | this variable is set to certain error values by many functions whenever an error has occurred |
fnmatch() | check the specified string to see if it matches the specified pattern |
fsys_fdinfo() | queries the server for information about the file associated with the file descriptor that belongs to process pid |
fsys_get_mount_dev() | find and return the device that a file is on |
fsys_get_mount_pt() | find and return the file system mount point (“directory”) associated with the named device |
fsys_fstat() | obtain detailed information about an open file |
fsys_stat() | obtain detailed information about a file |
fsysinfo() | return information from the file system manager for a file |
getopt() | a command-line parser that can be used by applications that follow guidelines 3,4,5,6,7,9 and 10 in POSIX Utility Syntax Guidelines 1003.2 2.11.2 |
getprio() | return the current priority of the specified process ID |
input_line() | get a string of characters from the specified file, and store it in the specified array |
mouse_close() | close a previously opened control channel to a mouse driver |
mouse_flush() | discard any pending mouse events in the mouse queue associated with the specified mouse control channel |
mouse_open() | open up a control channel to the mouse driver |
mouse_param() | set or query the current control parameters for the specified mouse |
mouse_read() | read up to n mouse events from the mouse server associated with the specified mouse control channel into the specified buffer |
print_usage() | print a program's usage message |
Readmsg() | read n bytes of data into a specified buffer from the process identified by the specified process ID |
Readmsgmx() | read data into a specified array of buffers from the process identified by the specified process ID |
Receive() | wait for a message from the process identified by the specified process ID |
Receivemx() | check to see if a message from the process identified by the specified process ID is waiting |
regcomp() | regular expression compiler |
regerror() | print an error string resulting from a regcomp() or regexec() call |
regexec() | compare the specified string against the compiled regular expression |
regfree() | release all memory allocated by the regular expression compiler |
Relay() | take the message received from the specified source process, and relay it to the specified target process |
Reply() | reply with a number of bytes of the specified data to the process identified by the specified process ID |
Replymx() | reply with a message taken from the specified array of message buffers to the process identified by the specified process ID |
Send() | send the specified message to the process identified by the specified process ID |
Sendfd() | send the specified message to the process associated with the specified file descriptor |
Sendfdmx() | send a message taken from the specified array of buffers to the process associated with the specified file descriptor |
Sendmx() | send a message taken from the specified array of buffers to the process identified by the specified process ID |
_setmx() | stuff the fields of a _mxfer_entry |
setprio() | change the priority of the process identified by the specified process ID to the specified priority |
Trace() | log timestamped events into a system trace buffer |
Trigger() | trigger the specified proxy to send a message to the process that owns it |
Writemsg() | write n bytes of data from the specified buffer to the reply message buffer identified by the specified process ID |
Writemsgmx() | write a message taken from the specified array of message buffers to the reply message buffer identified by the specified process ID |
Yield() | check to see if other processes at the same priority as that of the calling process are READY to run |
These functions provide the capability to invoke QNX functions directly from a program:
Function | Summary |
---|---|
qnx_device_attach() | attach a major device number to a resource manager |
qnx_device_detach() | detach a major device number from an I/O manager |
qnx_display_hex() | print a hexadecimal number on the screen of the physical console |
qnx_display_msg() | display a message on the screen of the physical console |
qnx_fd_attach() | get a new file descriptor |
qnx_fd_detach() | detach a file descriptor |
qnx_fd_query() | get information about a file descriptor |
qnx_fullpath() | expand a path into a full path |
qnx_getclock() | get the current time from a clock |
qnx_getids() | get IDs associated with a process |
qnx_hint_attach() | attach a handler function to a hardware interrupt |
qnx_hint_detach() | detach a handler from a hardware interrupt |
qnx_hint_mask() | query, enable or disable a hardware interrupt |
qnx_hint_query() | get information on the handler for a hardware interrupt |
qnx_ioctl() | issue special control requests to the driver for a file descriptor |
qnx_name_attach() | register a process under a given name |
qnx_name_detach() | remove the name associated with a process |
qnx_name_locate() | get the ID of the process registered under a given name |
qnx_name_locators() | get a list of nodes running global name locators |
qnx_name_nodes() | find a given name on all nodes |
qnx_net_alive() | determine the status of all nodes on the network |
qnx_name_query() | get information on a given name |
qnx_nidtostr() | convert a numeric node ID to a string |
qnx_osinfo() | get information on a given node ID |
qnx_osstat() | get the status of a node |
qnx_pflags() | examine and modify the systems flags word of a process |
qnx_prefix_attach() | attach a pathname prefix |
qnx_prefix_detach() | detach a pathname prefix |
qnx_prefix_getroot() | get the current network prefix root for the process |
qnx_prefix_query() | get a prefix tree below a given path on a given node |
qnx_prefix_setroot() | change the default network prefix for the process |
qnx_proxy_attach() | create a proxy to be attached to a process |
qnx_proxy_detach() | detach a proxy from a process |
qnx_proxy_rem_attach() | create a virtual proxy on a remote node |
qnx_proxy_rem_detach() | detach a virtual proxy on a remote node |
qnx_psinfo() | get information on a given process ID |
qnx_scheduler() | change the priority of a process |
qnx_segment_alloc() | allocate a segment of memory |
qnx_segment_alloc_flags() | allocate a segment of memory, specifying some option flags |
qnx_segment_arm() | arm a segment, so other processes can share it |
qnx_segment_flags() | change the access flags for a segment |
qnx_segment_free() | free a segment of memory |
qnx_segment_get() | get shared access to a segment |
qnx_segment_huge() | allocate a huge segment of memory |
qnx_segment_index() | get the segment associated with a given index into a segment table |
qnx_segment_info() | get information on a segment |
qnx_segment_overlay() | create a segment that overlays memory |
qnx_segment_overlay_flags() | create a segment that overlays memory, specifying some option flags |
qnx_segment_put() | give shared access to a segment |
qnx_segment_raw_alloc() | allocate a contiguous segment of memory, removing it from the system memory map |
qnx_segment_raw_free() | add a contiguous segment of memory to the system memory map |
qnx_segment_realloc() | change the size of a segment |
qnx_setclock() | set the current time of a clock |
qnx_setids() | change the real and effective user and group IDs of a process |
qnx_sflags() | examine and modify the system flags word on a node |
qnx_sid_query() | get information on a given session ID |
qnx_spawn() | create a new process |
qnx_spawn_options | a structure of global options for qnx_spawn() |
qnx_strtonid() | convert a string into a node ID |
qnx_sync() | request the file manager to flush all buffers |
qnx_ticksize() | set the system tick size |
qnx_trace_close() | close a channel to a trace buffer |
qnx_trace_info() | get information from a trace buffer |
qnx_trace_open() | open a channel to a trace buffer |
qnx_trace_read() | read events from a trace buffer |
qnx_trace_severity() | select the minimum severity of events to be traced |
qnx_trace_trigger() | cause a proxy to be triggered when the data in a trace buffer reaches a given level |
qnx_umask() | set the file mode creation mask for a process |
qnx_vc_attach() | establish a virtual circuit between two processes |
qnx_vc_detach() | free a virtual circuit between two processes |
qnx_vc_name_attach() | establish a virtual circuit to the process with a given name |
qnx_vc_poll_parm() | change the polling parameters for a virtual circuit |
These functions provide the capability to invoke Intel 80x86 processor-related functions directly from a program. Functions that apply to the Intel 8086 CPU apply to that family including the 80286, 80386, 80486 and Pentium processors. The following functions are defined:
Function | Summary |
---|---|
_CA_PCI_BIOS_Present() | determine whether or not PCI BIOS is present |
_CA_PCI_Find_Class() | find devices that have a specific class code |
_CA_PCI_Find_Device() | find the PCI device with a given device ID and vendor ID |
_CA_PCI_Read_Config_Byte() | read a byte from the configuration space of a device |
_CA_PCI_Read_Config_DWord() | read a double word from the configuration space of a device |
_CA_PCI_Read_Config_Word() | read a word from the configuration space of a device |
_CA_PCI_Generate_Special_Cycle() | generate a special cycle on a PCI bus |
_CA_PCI_Write_Config_Byte() | write individual bytes to the configuration space of a device |
_CA_PCI_Write_Config_DWord() | write individual double words to the configuration space of a device |
_CA_PCI_Write_Config_Word() | write individual words to the configuration space of a device |
_disable() | disable interrupts |
_enable() | enable interrupts |
FP_OFF() | get the offset part of a far pointer |
FP_SEG() | get the segment part of a far pointer |
inp() | get one byte from a hardware port |
inpw() | get two bytes (one word) from a hardware port |
int386() | cause a 386/486/Pentium CPU interrupt |
int386x() | cause a 386/486/Pentium CPU interrupt, with segment registers |
int86() | cause an 8086 CPU interrupt |
int86x() | cause an 8086 CPU interrupt, with segment registers |
intr() | cause an 8086 CPU interrupt, with segment registers |
MK_FP() | make a far pointer from the segment and offset values |
nosound() | turn off the speaker |
outp() | write one byte to a hardware port |
outpw() | write two bytes (one word) to a hardware port |
segread() | read segment registers |
sound() | turn on the speaker at the specified frequency |
The following functions are defined:
Function | Summary |
---|---|
closelog() | close the log file |
openlog() | set up the processing of messages for the log |
setlogmask() | set the log priority mask |
syslog() | write a message to the log |
vsyslog() | write a message to the log (varargs) |
The following functions are defined:
Function | Summary |
---|---|
assert() | test an assertion |
_fullpath() | return the full path specification for a file |
localeconv() | obtain locale-specific conversion information |
longjmp() | return and restore the environment saved by setjmp() |
_lrotl() | rotate an unsigned long to the left |
_lrotr() | rotate an unsigned long to the right |
offsetof() | get the offset of a field in a structure |
_rotl() | rotate an unsigned int to the left |
_rotr() | rotate an unsigned int to the right |
setjmp() | save the environment for use with longjmp() |
_makepath() | make a full filename from specified components |
setlocale() | set a locale |
sigsetjmp() | save the environment and the signal mask for a process, for use with the siglongjmp() function |
siglongjmp() | return and restore the environment and signal mask saved by sigsetjmp() |
_splitpath() | split a filename into its components |
_splitpath2() | split a filename into its components |
The following header files are supplied with the C library. As has been previously noted, when a library function is referenced in a source file, the related header files (shown in the synopsis for that function) should be included in that source file. The header files provide the proper declarations for the functions and for the number and types of arguments used with them. Constant values used in conjunction with the functions are also declared. The files can be included in any order.
When the Watcom C compiler option za is used (“ANSI conformance”), the macro NO_EXT_KEYS is predefined. The za option is used when you are creating an application that must conform to a certain standard, whether it be ANSI or POSIX. The effect on the inclusion of ANSI- and POSIX-defined header files is that certain portions of the header files are omitted:
Feature test macros may then be defined to select those portions that are omitted. Two feature test macros may be defined:
Feature test macros may be defined on the command line, or in the source file before any header files are included. The latter is illustrated in the following example, in which an ANSI- and POSIX-conforming application is being developed.
#define _POSIX_SOURCE #include <limits.h> #include <stdio.h> . . . #if defined(_QNX_SOURCE) #include "non_POSIX_header1.h" #include "non_POSIX_header2.h" #include "non_POSIX_header3.h" #endif
The source code is then compiled using the za option.
The following ANSI header files are affected by the _POSIX_SOURCE feature test macro:
The following ANSI and POSIX header files are affected by the _QNX_SOURCE feature test macro:
Header file | Type |
---|---|
ctype.h | ANSI |
env.h | POSIX |
fcntl.h | POSIX |
float.h | ANSI |
limits.h | ANSI |
math.h | ANSI |
process.h | extension to POSIX |
setjmp.h | ANSI |
signal.h | ANSI |
sys/stat.h | POSIX |
stdio.h | ANSI |
stdlib.h | ANSI |
string.h | ANSI |
termios.h | POSIX |
time.h | ANSI |
sys/types.h | POSIX |
unistd.h | POSIX |
The following header files are provided with the software. The header files that are located in the /usr/include directory are described first.
This ANSI header file is required when an assert() macro is used. These assertions are ignored when the identifier NDEBUG is defined.
This header file provides the declarations for console and Intel 80x86 port input/output functions.
This ANSI header file provides the declarations for functions that manipulate characters.
This header file contains definitions for the ncurses package.
This POSIX header file provides the declarations for functions related to directories, and for the type DIR, which describes an entry in a directory.
This POSIX header file contains prototypes for environment string functions.
This ANSI header file provides the extern declaration for error variable errno, and provides the symbolic names for error codes that can be placed in the error variable.
This header file contains definitions of error codes for the ncurses package.
This POSIX header file provides the flags used by the creat(), fcntl(), open() and sopen() functions.
This ANSI header file contains declarations for constants related to floating-point numbers, declarations for low-level floating-point functions, and the declaration of the floating-point exception codes.
This header file provides the declaration for the fnmatch() pattern-matching function.
This header file contains definitions of forms for the ncurses package.
This POSIX header file contains structures and prototypes for group operations.
This header file is used with functions that interact with the Intel architecture. It defines the structs and unions used to handle the input and output registers for the Intel 80x86 and 80386/80486 interrupt interface routines. It includes prototypes for the interrupt functions, definitions for the FP_OFF(), FP_SEG() and MK_FP() macros, and definitions for the following structures and unions:
This ANSI header file contains constant declarations for limits or boundary values for ranges of integers and characters.
This ANSI header file contains declarations for the categories (LC...) of locales that can be selected using the setlocale() function, which is also declared.
This header file provides declarations for the memory allocation and deallocation functions.
This ANSI header file contains declarations for the mathematical functions (which operate with floating-point numbers) and for the structures:
This header file contains definitions of menus for the ncurses package.
This header file contains declarations that are used by the functions that deal with message queues.
This header file contains definitions of panels for the ncurses package.
This header file contains function declarations for the spawn... functions, the exec... functions, and the system() function. The file also contains declarations for the constants P_WAIT, P_NOWAIT, P_NOWAITO and P_OVERLAY. These constants are discussed in the section on the spawn... functions.
This POSIX header file contains structure definitions and prototypes for password operations.
This header file contains structure definitions and prototypes for regular expression handling.
This header file contains function prototypes for the lfind() and lsearch() functions.
This header file conatins declarations used by the semaphore functions.
This ANSI header file provides declarations to be used with the setjmp() and longjmp() functions.
This header file defines constants for shared access to files using the sopen() function.
This ANSI header file contains the declarations related to the signal() and raise() functions.
This ANSI header file contains the declarations for the macros that handle variable argument lists.
This ANSI header file contains declarations for a few popular constants, including NULL (null pointer), size_t (unsigned size of an object), and ptrdiff_t (difference between two pointers). It also contains a declaration for the offsetof() macro.
This ANSI header file relates to “standard” input/output functions. Files, devices and directories are referenced using pointers to objects of the type FILE. The header file contains declarations for these functions and macros, defines the FILE type, and contains various constants related to files.
This ANSI header file contains declarations for many standard functions, excluding those declared in other header files discussed in this section.
This ANSI header file contains declarations for functions that manipulate strings or blocks of memory.
This header file contains definitions for the system message log.
This POSIX header file contains header block information for the tar format.
This header file contains terminal information definitions for use with ncurses.
If you want to continue to use termlib, you'll have to link it into your program explicitly with the option -ltermlib.
The file /usr/include/term.h is now an ncurses header file; you'll find the old term.h in /usr/include/sys/term.h. An error message is displayed if you combine the old term_* and ncurses header files.
This POSIX header file contains terminal I/O system types.
This ANSI header file declares the functions related to times and dates, and defines the structured type struct tm, which contains the following fields:
This header file contains definitions for displaying printable versions of control characters in the ncurses package.
This POSIX header file contains the declarations for functions that perform input/output operations at the operating system level. These functions use file descriptors to reference files or devices. The function fstat() is declared in the sys/stat.h header file.
This header file contains definitions that aid in porting traditional UNIX code.
This POSIX header file contains a declaration for the utime() function, and for the structured type utimbuf used by it. See the utime() function for a description of the utimbuf structure.
This UNIX System V header file provides an alternate way of handling variable argument lists. The equivalent ANSI header file is stdarg.h.
The following header files are present in the sys subdirectory. Their presence in this directory indicates that they are system-dependent header files.
This header file contains definitions for use with CD ROMs.
This header file contains definitions for the console driver.
This header file contains “public” definitions for the console driver.
This header file contains debugger data structures.
This header file contains “public” device administrator definitions.
This header file contains “public” device driver messages.
This header file contains non-portable file system definitions.
This header file contains the dumper file structure.
This header file contains file descriptor data structures.
This header file contains non-portable file system definitions.
This header file contains declarations related to the fsysinfo() function.
This header file contains non-portable file system message definitions.
This header file contains handy pragmas that are often used when doing low-level programming.
This header file contains non-portable low-level I/O definitions.
This header file contains structure definitions and prototypes for interrupt request functions.
This header file contains prototypes and pragmas for kernel function calls.
This header file contains structure definitions for load module format.
This header file contains the manifest constants used by the locking() function.
This header file contains a definition for the _magic structure.
This header file contains declarations related to the memory mapping functions.
At least the following protection bits are defined in sys/mman.h:
This header file contains structure definitions and prototypes for mouse operations.
This header file contains “private” definitions for the mouse driver.
This header file contains structure definitions and prototypes for QNX qnx_name... functions.
This header file contains manifests, structure definitions and prototypes for operating system information.
This header file contains manifests, structure definitions and prototypes for operating system status information.
This header file contains declarations for PCI functions.
This header file contains file prefix prototypes.
This header file contains process data structures and definitions.
This header file contains proxy process prototypes.
This header file contains manifests and structure definitions for process information.
This header files contains manifests and structures for common qnx_ioctl() messages.
This header file contains a structure definition for the QNX process-spawning global data area.
This header file contains terminal capability definitions.
This header file contains manifests and prototypes for process scheduling.
This header file contains segment information data structures.
This header file contains the prototype for the select() function.
This header file contains a definition for _setmx(), and a definition of the _mxfer_entry structure. See _setmx() for a description of the _mxfer_entry structure.
This header file contains “public” serial driver messages.
This header file contains session information data structures.
This POSIX header file contains the declarations pertaining to file status, including definitions for the fstat() and stat() functions and for the structure:
This header file also defines access permission bits for the owner of a file, the owner's group, and other users.
The following bits define permissions for the owner:
Bit | Meaning |
---|---|
S_IRWXU | Read, write, execute/search |
S_IRUSR | Read permission |
S_IWUSR | Write permission |
S_IXUSR | Execute/search permission |
S_IRWXU is the bitwise inclusive OR of S_IRUSR, S_IWUSR, and S_IXUSR.
The following bits define permissions for the group:
Bit | Meaning |
---|---|
S_IRWXG | Read, write, execute/search |
S_IRGRP | Read permission |
S_IWGRP | Write permission |
S_IXGRP | Execute/search permission |
S_IRWXG is the bitwise inclusive OR of S_IRGRP, S_IWGRP and S_IXGRP.
The following bits define permissions for others:
Bit | Meaning |
---|---|
S_IRWXO | Read, write, execute/search |
S_IROTH | Read permission |
S_IWOTH | Write permission |
S_IXOTH | Execute/search permission |
S_IRWXO is the bitwise inclusive OR of S_IROTH, S_IWOTH and S_IXOTH.
The following bits define miscellaneous permissions used by other implementations:
Bit | Meaning |
---|---|
S_IREAD | is equivalent to S_IRUSR (read permission) |
S_IWRITE | is equivalent to S_IWUSR (write permission) |
S_IEXEC | is equivalent to S_IXUSR (execute/search permission) |
This header file contains standard system message definitions.
This header file contains terminal information definitions for use with the QNX proprietary term_* functions.
If you want to continue to use termlib, you'll have to link it into your program explicitly with the option -ltermlib.
The file /usr/include/term.h is now an ncurses header file; you'll find the old term.h in /usr/include/sys/term.h. An error message is displayed if you combine the old term_* and ncurses header files.
This header file describes the timeb structure used in conjunction with the ftime() function. See the description of ftime() for a description of this structure.
This POSIX header file contains interval timer definitions from POSIX 1003.4.
This POSIX header file contains process timing definitions from POSIX 1003.1.
This header file contains trace data structures and definitions. These are described with the Trace() functions.
This header file contains the trace codes used by the Trace() functions. These are described with the Trace() functions.
This POSIX header file contains declarations for the types used by system-level calls to obtain file status or time information.
This file contains definitions for SCSI I/O control.
This header file contains declarations related to the readv() and writev() functions.
This POSIX header file contains a definition of the utsname structure, and a prototype for the uname() function. See the description of uname() for more information on this structure.
This header file contains manifests and prototypes for virtual circuit functions.
This POSIX header file contains manifests and prototypes for the wait() and waitpid() functions.
The following headers are included in order to resolve references to items found on other operating systems. They may be helpful when porting code.
Certain data items are used by the Watcom C/C++ run-time library and may be inspected (or changed in some cases) by a program. The defined items are:
In the 16-bit libraries, __threadid is a far pointer to an int. In the 32-bit libraries, it's a function that returns an int.
The TZ environment variable is used to establish the local time zone. The value of the variable is used by various time functions to compute times relative to Coordinated Universal Time (UTC) (formerly known as Greenwich Mean Time (GMT)).
The time on the computer should be set to UTC. Use the date command if the time isn't automatically maintained by the computer hardware.
The TZ environment variable can be set (before the program is executed) by using
or (during the program execution) by using the setenv() or putenv() library functions:
setenv( "TZ", "PST8PDT", 1 ); putenv( "TZ=PST8PDT" );
The value of the variable can be obtained by using the getenv() function:
char *tzvalue; ... tzvalue = getenv( "TZ" );
The tzset() function processes the TZ environment variable, and sets the following global variables:
The value of the TZ environment variable should be set as follows (spaces are for clarity only):
std offset dst offset, rule
The expanded format is as follows:
stdoffset[dst[offset][,start[/time],end[/time]]]
where
hh[:mm[:ss]]
The minutes (mm) and seconds (ss) are optional. The hour (hh) is required, and may be a single digit.
The offset following std is required. If no offset follows dst, summer time is assumed to be one hour ahead of standard time.
One or more digits may be used; the value is always interpreted as a decimal number. The hour may be between 0 and 24, and the minutes (and seconds) — if present — between 0 and 59. If preceded by a “-”, the time zone is east of the Prime Meridian; otherwise it's west (which may be indicated by an optional preceding “+”).
date/time,date/time
where the first date describes when the change from standard to summer time occurs, and the second date describes when the change back happens. Each time field describes when, in current local time, the change to the other time is made.
The format of date may be one of the following:
The time has the same format as offset, except that no leading sign (“+” or “-”) is allowed. The default, if time is omitted, is 02:00:00.
Whenever ctime(), _ctime(), localtime(), _localtime() or mktime() is called, the time zone names contained in the external variable tzname are set as if the tzset() function had been called. The same is true if the %Z directive of strftime() is used.
Some examples are given below.