C Library Overview

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:

Classes of Functions

The functions in the Watcom C library can be organized into a number of classes:

Character Manipulation Functions
These functions deal with single characters.
Memory Manipulation Functions
These functions manipulate blocks of memory.
String Manipulation Functions
These functions manipulate strings of characters. A character string is an array of zero or more adjacent characters followed by a null character ('\0') that marks the end of the string.
Multibyte Character Functions
These ANSI C functions provide capabilities for processing multibyte and wide characters.
Conversion Functions
These functions convert values from one representation to another. Numeric values, for example, can be converted to strings.
Memory Allocation Functions
These functions are concerned with allocating and deallocating memory.
Heap Functions
These functions provide the ability to shrink and grow the heap, as well as to find heap-related problems.
Math Functions
The mathematical functions perform mathematical computations such as the common trigonometric calculations. These functions operate on double values, also known as floating-point values.
Searching Functions
These functions provide searching and sorting capabilities.
Time Functions
These functions provide facilities to obtain and manipulate times and dates.
Variable-length Argument Lists
These functions provide the capability to process a variable number of arguments to a function.
Stream I/O Functions
These functions provide the “standard” functions to read and write files. Data can be transmitted as characters, strings, blocks of memory or under format control.
Process Primitive Functions
These functions deal with process creation, execution and termination, signal handling, and timer operations.
Process Environment
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.
Directory Functions
These functions provide directory services.
Operating System I/O Functions
These functions are described in the IEEE Standard Portable Operating System Interface for Computer Environments (POSIX 1003.1). The POSIX input/output functions provide the capability to perform I/O at a lower level than the C Language stream I/O functions (for example, fopen(), fread(), fwrite() and fclose()).
File Manipulation Functions
These functions operate directly on files, providing facilities such as the deletion of files.
Console I/O Functions
These functions provide the capability to read and write characters directly from the console.
POSIX Message Queues
These functions deal with message queues.
POSIX Realtime Timer Functions
These functions provide realtime timer capabilities.
POSIX Semaphore Functions
These functions deal with semaphores.
POSIX Shared Memory Functions
These functions provide memory mapping capabilities.
POSIX Terminal Control Functions
These functions deal with terminal attributes, such as baud rate and terminal interface control functions.
System Database Functions
These functions allow an application to access group and user database information.
Miscellaneous QNX Functions
These functions provide access to a variety of QNX functions, such as message passing.
QNX Low-level Functions
These functions provide access to low-level QNX facilities.
Intel 80x86 Architecture-Specific Functions
This set of functions allows access to Intel 80x86 processor-related functions.
System Message Log functions
This set of functions controls the system log.
Miscellaneous Functions
This collection consists of the remaining functions.

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.

Character Manipulation Functions

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

Memory Manipulation Functions

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.

String Manipulation Functions

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:

Conversion Functions
conversions to and from strings
Time Functions
formatting of dates and times
Memory Manipulation Functions
operating on arrays without a terminating null character

Multibyte Character Functions

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

Conversion Functions

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:

Memory Allocation Functions

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 _nfree() function should be used to free space acquired by the _ncalloc(), _nmalloc(), or _nrealloc() functions
  • the _ffree() function should be used to free space acquired by the _fcalloc(), _fmalloc(), or _frealloc() functions
  • the _bfree() function should be used to free space acquired by the _bcalloc(), _bmalloc(), or _brealloc() functions.

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 _fmalloc() and _nmalloc() functions can both be used in either data memory model.

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

Heap Functions

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

Math Functions

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

Searching 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

Time Functions

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

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

Stream I/O Functions

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:

stdin
Standard Input: input from the console
stdout
Standard Output: output to the console
stderr
Standard Error: output to the console (used for error messages)

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.

Process Primitive Functions

These functions deal with process creation, execution and termination, signal handling, and timer operations.

The QNX libraries currently aren't completely thread-safe. If you need to use this functionality, contact Technical Support to see if newer versions of the libraries are available.

When a new process is started, it replaces the existing process in the following cases:

  • P_OVERLAY is specified with the spawn...() functions
  • the exec...() routines are invoked

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:

  • P_WAIT is specified with the spawn...() functions
  • system() is used

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:

  • l or v (one is required) to indicate the way the process parameters are passed
  • p (optional) to indicate that the PATH environment variable is searched to locate the program for the process
  • e (optional) to indicate that the environment variables are being passed

Process Environment

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

Directory Functions

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

Operating System I/O Functions

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

File Manipulation Functions

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

Console I/O Functions

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

POSIX Message Queues

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

POSIX Realtime Timer Functions

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

POSIX Semaphore Functions

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

POSIX Shared Memory Functions

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

POSIX Terminal Control Functions

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

System Database Functions

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

Miscellaneous QNX Functions

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

QNX Low-level Functions

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

Intel 80x86 Architecture-Specific Functions

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

System Message Log Functions

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)

Miscellaneous Functions

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

Header Files

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:

  • for ANSI header files, these are the portions that go beyond the ANSI standard
  • for POSIX header files, these are the portions that go beyond the POSIX standard

Feature test macros may then be defined to select those portions that are omitted. Two feature test macros may be defined:

_POSIX_SOURCE
Include those portions of the ANSI header files that relate to the POSIX standard (IEEE Standard Portable Operating System Interface for Computer Environments - POSIX 1003.1)
_QNX_SOURCE
Include those portions of the ANSI and POSIX header files that relate to the POSIX standard and all extensions provided by the QNX system. In essence, the definition of _QNX_SOURCE before any header files are included is equivalent to omitting the specification of the za compiler option. When _QNX_SOURCE is defined, it encompasses _POSIX_SOURCE, so it isn't necessary to define _POSIX_SOURCE as well.

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:

  • limits.h
  • setjmp.h
  • signal.h
  • stdio.h
  • stdlib.h
  • time.h

The following ANSI and POSIX header files are affected by the _QNX_SOURCE feature test macro:

Header fileType
ctype.hANSI
env.hPOSIX
fcntl.hPOSIX
float.hANSI
limits.hANSI
math.hANSI
process.hextension to POSIX
setjmp.hANSI
signal.hANSI
sys/stat.hPOSIX
stdio.hANSI
stdlib.hANSI
string.hANSI
termios.hPOSIX
time.hANSI
sys/types.hPOSIX
unistd.hPOSIX

Header Files in /usr/include

The following header files are provided with the software. The header files that are located in the /usr/include directory are described first.

assert.h

This ANSI header file is required when an assert() macro is used. These assertions are ignored when the identifier NDEBUG is defined.

conio.h

This header file provides the declarations for console and Intel 80x86 port input/output functions.

ctype.h

This ANSI header file provides the declarations for functions that manipulate characters.

curses.h

This header file contains definitions for the ncurses package.

The QNX proprietary term_* functions have been deprecated in favor of ncurses. ncurses is a set of terminal-independent routines for painting screens and handling input events. It's a freeware implementation that's based on the System V and X/Open curses API. For more information, see the Miscellaneous Utilities bookset in the online documentation.

dirent.h

This POSIX header file provides the declarations for functions related to directories, and for the type DIR, which describes an entry in a directory.

env.h

This POSIX header file contains prototypes for environment string functions.

errno.h

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.

eti.h

This header file contains definitions of error codes for the ncurses package.

fcntl.h

This POSIX header file provides the flags used by the creat(), fcntl(), open() and sopen() functions.

float.h

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.

fnmatch.h

This header file provides the declaration for the fnmatch() pattern-matching function.

form.h

This header file contains definitions of forms for the ncurses package.

grp.h

This POSIX header file contains structures and prototypes for group operations.

i86.h

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:

REGS
describes the CPU registers for Intel 8086 family.
SREGS
describes the segment registers for the Intel 8086 family.
REGPACK
describes the CPU registers and segment registers for Intel 8086 family.
INTPACK
describes the input parameter to an “interrupt” function.

limits.h

This ANSI header file contains constant declarations for limits or boundary values for ranges of integers and characters.

locale.h

This ANSI header file contains declarations for the categories (LC...) of locales that can be selected using the setlocale() function, which is also declared.

malloc.h

This header file provides declarations for the memory allocation and deallocation functions.

math.h

This ANSI header file contains declarations for the mathematical functions (which operate with floating-point numbers) and for the structures:

exception
describes the exception structure passed to the matherr() function; symbolic constants for the types of exceptions are included
complex
declares a complex number. See cabs() for more information.

menu.h

This header file contains definitions of menus for the ncurses package.

mqueue.h

This header file contains declarations that are used by the functions that deal with message queues.

panel.h

This header file contains definitions of panels for the ncurses package.

process.h

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.

pwd.h

This POSIX header file contains structure definitions and prototypes for password operations.

regex.h

This header file contains structure definitions and prototypes for regular expression handling.

search.h

This header file contains function prototypes for the lfind() and lsearch() functions.

semaphore.h

This header file conatins declarations used by the semaphore functions.

setjmp.h

This ANSI header file provides declarations to be used with the setjmp() and longjmp() functions.

share.h

This header file defines constants for shared access to files using the sopen() function.

signal.h

This ANSI header file contains the declarations related to the signal() and raise() functions.

stdarg.h

This ANSI header file contains the declarations for the macros that handle variable argument lists.

stddef.h

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.

stdio.h

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.

stdlib.h

This ANSI header file contains declarations for many standard functions, excluding those declared in other header files discussed in this section.

string.h

This ANSI header file contains declarations for functions that manipulate strings or blocks of memory.

syslog.h

This header file contains definitions for the system message log.

tar.h

This POSIX header file contains header block information for the tar format.

term.h

This header file contains terminal information definitions for use with ncurses.

The QNX proprietary term_* functions have been deprecated in favor of ncurses. ncurses is a set of terminal-independent routines for painting screens and handling input events. It's a freeware implementation that's based on the System V and X/Open curses API. For more information, see the Miscellaneous Utilities bookset in the online documentation.

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.

termios.h

This POSIX header file contains terminal I/O system types.

time.h

This ANSI header file declares the functions related to times and dates, and defines the structured type struct tm, which contains the following fields:

int tm_sec
seconds after the minute, in the range [0,61], allowing for leap seconds
int tm_min
minutes after the hour, in the range [0,59]
int tm_hour
hours after midnight, in the range [0,23]
int tm_mday
day of the month, in the range [1,31]
int tm_mon
months since January, in the range [0,11]
int tm_year
years since 1900
int tm_wday
days since Sunday, in the range [0,6]
int tm_yday
days since January 1, in the range [0,365], allowing for leap years
int tm_isdst
Daylight Savings Time flag

unctrl.h

This header file contains definitions for displaying printable versions of control characters in the ncurses package.

unistd.h

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.

unix.h

This header file contains definitions that aid in porting traditional UNIX code.

utime.h

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.

varargs.h

This UNIX System V header file provides an alternate way of handling variable argument lists. The equivalent ANSI header file is stdarg.h.

Header Files in /usr/include/sys

The following header files are present in the sys subdirectory. Their presence in this directory indicates that they are system-dependent header files.

sys/cdrom.h

This header file contains definitions for use with CD ROMs.

sys/con_msg.h

This header file contains definitions for the console driver.

sys/console.h

This header file contains “public” definitions for the console driver.

sys/debug.h

This header file contains debugger data structures.

sys/dev.h

This header file contains “public” device administrator definitions.

sys/dev_msg.h

This header file contains “public” device driver messages.

sys/disk.h

This header file contains non-portable file system definitions.

sys/dumper.h

This header file contains the dumper file structure.

sys/fd.h

This header file contains file descriptor data structures.

sys/fsys.h

This header file contains non-portable file system definitions.

sys/fsysinfo.h

This header file contains declarations related to the fsysinfo() function.

sys/fsys_msg.h

This header file contains non-portable file system message definitions.

sys/inline.h

This header file contains handy pragmas that are often used when doing low-level programming.

sys/io_msg.h

This header file contains non-portable low-level I/O definitions.

sys/irqinfo.h

This header file contains structure definitions and prototypes for interrupt request functions.

sys/kernel.h

This header file contains prototypes and pragmas for kernel function calls.

sys/lmf.h

This header file contains structure definitions for load module format.

sys/locking.h

This header file contains the manifest constants used by the locking() function.

sys/magic.h

This header file contains a definition for the _magic structure.

sys/mman.h

This header file contains declarations related to the memory mapping functions.

At least the following protection bits are defined in sys/mman.h:

PROT_EXEC
The region can be executed.
PROT_NOCACHE
Disable caching of the region (for example, can be used to access dual ported memory).
PROT_NONE
The region cannot be accessed.
PROT_READ
The region can be read.
PROT_WRITE
The region can be written.

sys/mouse.h

This header file contains structure definitions and prototypes for mouse operations.

sys/mous_msg.h

This header file contains “private” definitions for the mouse driver.

sys/name.h

This header file contains structure definitions and prototypes for QNX qnx_name... functions.

sys/osinfo.h

This header file contains manifests, structure definitions and prototypes for operating system information.

sys/osstat.h

This header file contains manifests, structure definitions and prototypes for operating system status information.

sys/pci.h

This header file contains declarations for PCI functions.

sys/prfx.h

This header file contains file prefix prototypes.

sys/proc_msg.h

This header file contains process data structures and definitions.

sys/proxy.h

This header file contains proxy process prototypes.

sys/psinfo.h

This header file contains manifests and structure definitions for process information.

sys/qioctl.h

This header files contains manifests and structures for common qnx_ioctl() messages.

sys/qnx_glob.h

This header file contains a structure definition for the QNX process-spawning global data area.

sys/qnxterm.h

This header file contains terminal capability definitions.

sys/sched.h

This header file contains manifests and prototypes for process scheduling.

sys/seginfo.h

This header file contains segment information data structures.

sys/select.h

This header file contains the prototype for the select() function.

sys/sendmx.h

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.

sys/ser_msg.h

This header file contains “public” serial driver messages.

sys/sidinfo.h

This header file contains session information data structures.

sys/stat.h

This POSIX header file contains the declarations pertaining to file status, including definitions for the fstat() and stat() functions and for the structure:

stat
describes the information obtained for a directory, file or device

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)

sys/sys_msg.h

This header file contains standard system message definitions.

sys/term.h

This header file contains terminal information definitions for use with the QNX proprietary term_* functions.

The QNX proprietary term_* functions have been deprecated in favor of ncurses. ncurses is a set of terminal-independent routines for painting screens and handling input events. It's a freeware implementation that's based on the System V and X/Open curses API. For more information, see the Miscellaneous Utilities bookset in the online documentation.

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.

sys/timeb.h

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.

sys/timers.h

This POSIX header file contains interval timer definitions from POSIX 1003.4.

sys/times.h

This POSIX header file contains process timing definitions from POSIX 1003.1.

sys/trace.h

This header file contains trace data structures and definitions. These are described with the Trace() functions.

sys/tracecod.h

This header file contains the trace codes used by the Trace() functions. These are described with the Trace() functions.

sys/types.h

This POSIX header file contains declarations for the types used by system-level calls to obtain file status or time information.

sys/uscsi.h

This file contains definitions for SCSI I/O control.

sys/uio.h

This header file contains declarations related to the readv() and writev() functions.

sys/utsname.h

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.

sys/vc.h

This header file contains manifests and prototypes for virtual circuit functions.

sys/wait.h

This POSIX header file contains manifests and prototypes for the wait() and waitpid() functions.

Header Files Provided for Compatibility

The following headers are included in order to resolve references to items found on other operating systems. They may be helpful when porting code.

  • /usr/include/ftw.h
  • /usr/include/ioctl.h
  • /usr/include/libc.h
  • /usr/include/sgtty.h
  • /usr/include/shadow.h
  • /usr/include/termcap.h
  • /usr/include/termio.h
  • /usr/include/ustat.h
  • /usr/include/utmp.h
  • /usr/include/sys/dir.h
  • /usr/include/sys/file.h
  • /usr/include/sys/ioctl.h
  • /usr/include/sys/statfs.h
  • /usr/include/sys/termio.h
  • /usr/include/sys/time.h

Global Data

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:

_amblksiz
Prototype in stdlib.h. This unsigned int data item contains the increment by which the “break” pointer for memory allocation is advanced when there's no freed block large enough to satisfy a request to allocate a block of memory. This value may be changed by a program at any time.
_argc
This int item contains the number of arguments passed to main().
_argv
This char ** item contains a pointer to a vector containing the actual arguments passed to main().
daylight
Prototype in time.h. This unsigned int has a value of one when daylight saving time is supported in this locale, and zero otherwise. Whenever a time function is called, the tzset() function is called to set the value of the variable. The value is determined from the value of the TZ environment variable.
environ
Prototype in stdlib.h. This char ** __near data item is a pointer to an array of character pointers to the environment strings.
errno
Prototype in errno.h. This int item contains the number of the last error that was detected. The run-time library never resets errno to 0. Symbolic names for these errors are found in the errno.h header file. See the description of errno in the chapter Library Functions and Macros for more information. See the section “Messages Generated by the perror() Function” in Appendix A: Implemenation-defined Behavior for information about the text that describes these errors.
fltused_
The C compiler places a reference to the fltused_ symbol into any module that uses a floating-point library routine or library routine that requires floating-point support (for example, the use of a float or double as an argument to the printf() function).
_osmajor
Prototype in stdlib.h. This unsigned char variable contains the major number for the version of QNX executing on the computer. If the current version is 4.10, then the value is 4.
_osminor
Prototype in stdlib.h. This unsigned char variable contains the minor number for the version of QNX executing on the computer. If the current version is 4.10, then the value is 10.
stderr
Prototype in stdio.h. This variable (with type FILE *) indicates the standard error stream (set to the console by default).
stdin
Prototype in stdio.h. This variable (with type FILE *) indicates the standard input stream (set to the console by default).
stdout
Prototype in stdio.h. This variable (with type FILE *) indicates the standard output stream (set to the console by default).
_threadid
Prototype in stddef.h. This variable/function can be used to obtain the ID of the current thread, which is an int.

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 QNX libraries currently aren't completely thread-safe. If you need to use this functionality, contact Technical Support to see if newer versions of the libraries are available.
timezone
Prototype in time.h. This long int contains the number of seconds of time that the local time zone is earlier than Coordinated Universal Time (UTC) (formerly known as Greenwich Mean Time (GMT)). Whenever a time function is called, the tzset() function is called to set the value of the variable. The value is determined from the value of the TZ environment variable.
tzname
Prototype in time.h. This array of two pointers to character strings indicates the name of the standard abbreviation for the time zone and the name of the abbreviation for the time zone when daylight saving time is in effect. Whenever a time function is called, the tzset() function is called to set the values in the array. These values are determined from the value of the TZ environment variable.

The TZ Environment Variable

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

  • the env utility (for example, env TZ=PST8PDT)
  • the export shell command (for example, export TZ=PST8PDT)

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:

daylight
indicates if daylight saving time is supported in the locale
timezone
contains the number of seconds of time difference between the local time zone and Coordinated Universal Time (UTC)
tzname
a vector of two pointers to character strings containing the standard and daylight time-zone names

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

std, dst
are three or more letters that are the designation for the standard (std) or summer (dst) time zone. Only std is required. If dst is omitted, then summer time doesn't apply in this locale. Upper- and lowercase letters are allowed. Any characters except for a leading colon (:), digits, comma (,), minus (-), plus (+), and ASCII NUL (\0) are allowed.
offset
indicates the value one must add to the local time to arrive at Coordinated Universal Time (UTC). The offset has the form:

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 “+”).

rule
indicates when to change to and back from summer time. The rule has the form:

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:

Jn
The Julian day n (1 <= n <= 365). Leap days aren't counted. That is, in all years — including leap years — February 28 is day 59 and March 1 is day 60. It is impossible to refer explicitly to the occasional February 29.
n
The zero-based Julian day (0 <= n <= 365). Leap years are counted, and it is possible to refer to February 29.
Mm.n.d
The dth day (0 <= d <= 6) of week n of month m of the year (1 <= n <= 5, 1 <= m <= 12, where week 5 means “the last d day in month m”, which may occur in the fourth or fifth week). Week 1 is the first week in which the dth day occurs. Day zero is Sunday.

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.

  1. TZ=EST5EDT
    • Eastern Standard Time is 5 hours earlier than Coordinated Universal Time (UTC). Standard time and daylight saving time both apply to this locale.
    • By default, Eastern Daylight Time (EDT) is one hour ahead of standard time (that is, EDT4).
    • Since it isn't specified, daylight saving time starts on the first Sunday of April at 2:00 A.M., and ends on the last Sunday of October at 2:00 A.M.
    This is the default when the TZ variable isn't set.
  2. TZ=EST5EDT4,M4.1.0/02:00:00,M10.5.0/02:00:00 This is the full specification for the default when the TZ variable isn't set.
    • Eastern Standard Time is 5 hours earlier than Coordinated Universal Time (UTC).
    • Standard time and daylight saving time both apply to this locale.
    • Eastern Daylight Time (EDT) is one hour ahead of standard time.
    • Daylight saving time starts on the first (1) Sunday (0) of April (4) at 2:00 A.M., and ends on the last (5) Sunday (0) of October (10) at 2:00 A.M.
  3. TZ=PST8PDT
    • Pacific Standard Time is 8 hours earlier than Coordinated Universal Time (UTC).
    • Standard time and daylight saving time both apply to this locale.
    • By default, Pacific Daylight Time is one hour ahead of standard time (that is, PDT7).
    • Since it isn't specified, daylight saving time starts on the first Sunday of April at 2:00 A.M., and ends on the last Sunday of October at 2:00 A.M.
  4. TZ=NST3:30NDT1:30
    • Newfoundland Standard Time is 3 and 1/2 hours earlier than Coordinated Universal Time (UTC).
    • Standard time and daylight saving time both apply to this locale.
    • Newfoundland Daylight Time is 1 and 1/2 hours earlier than Coordinated Universal Time (UTC).
  5. TZ=Central Europe Time-2:00
    • Central European Time is 2 hours later than Coordinated Universal Time (UTC).
    • Daylight saving time doesn't apply in this locale.