gtpc2mj6C/C++ Language Support User's Guide

TPF File System C Functions

TPF file system C functions operate through the TPF stream I/O support. Table 50 lists these functions.

Note:
All file system application programming interfaces (APIs) are atomic and are completed when control returns to the caller. File system APIs that are called within an application commit scope are not part of that commit scope. A device driver can be written so an update to a special file is within the application commit scope. See User-Defined Device Driver Functions for more information.

Table 50. TPF File System C Functions

C function Description C Header File Standards
access Determine Whether a File Can Be Accessed unistd.h POSIX.1 (5.6.3)
atexit Register Program Termination Function stdlib.h ANSI/ISO (7.10.4.2)
chdir Change the Working Directory unistd.h POSIX.1 (5.2.1)
chmod Change the Mode of a File or Directory sys/stat.h POSIX.1 (5.6.4)
chown Change the Owner or Group of a File or Directory unistd.h POSIX.1 (5.6.5)
clearerr Reset Error and End-of-File stdio.h ISO-C (7.9.10.1)
close Close a File unistd.h POSIX.1 (6.3.1)
closedir Close a Directory sys/types.h
dirent.h
POSIX.1 (5.1.2)
creat Create a New File or Rewrite an Existing One sys/types.h
sys/stat.h
fcntl.h
POSIX.1 (5.3.2)
dup Duplicate an Open File Descriptor unistd.h POSIX.1 (6.2.1)
dup2 Duplicate an Open File Descriptor to Another unistd.h POSIX.1 (6.2.1)
fchmod Change the Mode of a File or Directory by File Descriptor sys/stat.h POSIX.1 (5.6.4)
fchown Change the Owner or Group by File Descriptor unistd.h POSIX.1a (5.6.5)
fclose Close a File stdio.h ISO-C (7.9.5.1)
POSIX.1 (8.2.3.2)
fcntl Control Open File Descriptors sys/types.h
unistd.h
fcntl.h
POSIX.1 (6.5.2)
fdopen Associate a Stream with an Open File Descriptor stdio.h POSIX.1 (8.2.2)
feof Test End-of-File Indicator stdio.h ISO-C (7.9.10.2)
ferror Test for Read/Write Errors stdio.h ISO-C (7.9.10.3)
fflush Write a Buffer to File stdio.h ISO-C (7.9.5.2)
POSIX.1 (8.2.3.4)
fgetc Read a Character stdio.h ISO-C (7.9.7.1)
POSIX.1 (8.2.3.5)
fgetpos Get File Position stdio.h ISO-C (7.9.9.1)
fgets Read a String from a Stream stdio.h ISO-C (7.9.7.2)
POSIX.1 (8.2.3.5)
fileno Get the File Descriptor from an Open Stream stdio.h POSIX.1 (8.2.1)
fopen Open a File stdio.h ISO-C (7.9.5.3)
POSIX.1 (8.2.3.1)
fprintf Format and Write Data to a Stream stdio.h ISO-C (7.9.6.1)
POSIX.1 (8.2.3.6)
fputc Write a Character stdio.h ISO-C (7.9.7.3)
POSIX.1 (8.2.3.6)
fputs Write a String to a Stream stdio.h ISO-C (7.9.7.4)
POSIX.1 (8.2.3.6)
fread Read Items stdio.h ISO-C (7.9.8.1)
POSIX.1 (8.2.3.5)
freopen Redirect an Open File stdio.h ISO-C (7.9.5.4)
POSIX.1 (8.2.3.3)
fscanf Read and Format Data from a Stream stdio.h ISO-C (7.9.6.2)
POSIX.1 (8.2.3.5)
fseek Set the File Position stdio.h ISO-C (7.9.9.2)
POSIX.1 (8.2.3.7)
fsetpos Set File Position stdio.h ISO-C (7.9.9.3)
fstat Get Status Information about a File sys/types.h
sys/stat.h
POSIX.1 (5.6.2)
fsync Write Changes to Direct-Access Storage unistd.h POSIX.1b (6.6.1)
ftell Get Current File Position stdio.h ISO-C (7.9.9.4)
POSIX.1 (8.2.3.10)
ftruncate Truncate a File unistd.h POSIX.1b (5.6.7)
fwrite Write Items stdio.h ISO-C (7.9.8.2)
POSIX.1 (8.2.3.6)
getc Read a Character from a Stream stdio.h ISO-C (7.9.7.5)
POSIX.1 (8.2.3.5)
getchar Read a Character from the Standard Input Stream stdio.h ISO-C (7.9.7.6)
POSIX.1 (8.2.3.5)
getcwd Get Path Name of the Current Working Directory unistd.h POSIX.1 (5.2.2)
link Create a Link to a File unistd.h POSIX.1 (5.3.4)
lseek Change the Offset of a File unistd.h
sys/types.h
POSIX.1 (6.5.3)
lstat Get the Status of a File or Symbolic Link sys/types.h
sys/stat.h
POSIX.1a (5.6.2)
mkdir Make a Directory sys/stat.h POSIX.1 (5.4.1)
mkfifo Make a FIFO Special File sys/stat.h
sys/types.h
POSIX.1 (5.4.2)
mknod Make a Special File sys/stat.h
open Open a File fcntl.h
sys/stat.h
sys/types.h
POSIX.1 (5.3.1)
opendir Open a Directory sys/types.h
dirent.h
POSIX.1 (5.1.2)
pipe Create an Unnamed Pipe unistd.h
POSIX.1 (6.1.1)
putc Write a Character to a Stream stdio.h ISO-C (7.9.7.8)
POSIX.1 (8.2.3.6)
putchar Write a Character to the Standard Output Stream stdio.h ISO-C (7.9.7.9)
POSIX.1 (8.2.3.6)
read Read a File unistd.h POSIX.1 (6.4.1)
readdir Read an Entry from a Directory sys/types.h
dirent.h
POSIX.1 (5.1.2)
readlink Read the Value of a Symbolic Link unistd.h POSIX.1a (5.3.5)
remove Delete a File stdio.h ISO-C (7.9.4.1)
POSIX.1 (8.2.4)
rename Rename a File stdio.h ISO-C (7.9.4.2)
POSIX.1 (5.5.3)
rewind Set File Position to Beginning of File stdio.h ISO-C (7.9.9.5)
POSIX.1 (8.2.3.7)
rewinddir Reposition a Directory Stream to the Beginning sys/types.h
dirent.h
POSIX.1 (5.1.2)
rmdir Remove a Directory unistd.h POSIX.1 (5.5.2)
setbuf Control Buffering stdio.h ISO-C (7.9.5.5)
setvbuf Control Buffering Strategy and Buffer Size stdio.h ISO-C (7.9.5.6)
sprintf Format and Write Data to a String stdio.h ISO-C (7.9.6.5)
sscanf Read and Format Data from a Buffer stdio.h ISO-C (7.9.6.6)
stat Get File Information sys/types.h
sys/stat.h
POSIX.1 (5.6.2)
symlink Create a Symbolic Link to a Path Name unistd.h POSIX.1a (5.3.6)
system Execute a Command stdlib.h ISO-C (7.10.4.5)
POSIX.1a (8.1.5)
tmpfile Create a Temporary File stdio.h ISO-C (7.9.4.3)
POSIX.1 (8.2.3.9)
tmpnam Produce a Temporary File Name stdio.h ISO-C (7.9.4.4)
umask Set or Display the File Mode Creation Mask sys/stat.h
sys/types.h
POSIX.1 (5.3.3)
ungetc Push Character onto an Input Stream stdio.h ISO-C (7.9.7.11)
unlink Remove a Directory Entry unistd.h POSIX.1 (5.5.1)
utime Set File Access and Modification Times utime.h
sys/types.h
POSIX.1 (5.6.6)
vfprintf Format and Write Data to a Stream stdarg.h
stdio.h
ISO-C (7.9.6.7)
POSIX.1 (8.2.3.6)
vprintf Format and Write Data to the Standard Output Stream stdarg.h
stdio.h
ISO-C (7.9.6.8)
POSIX.1 (8.2.3.6)
vsprintf Format and Write Data to Buffer stdarg.h
stdio.h
ISO-C (7.9.6.9)
write Write a File unistd.h POSIX.1 (6.4.2)
Note:
Sockets also supports the close, read, and write C functions.
Note:
References to standards:

ISO-C
ISO-C Standard, International Standard ISO/IEC 9899:1990 and American National Standard for Programming Languages---C, ANSI/ISO 9899-1990

POSIX.1
Information Technology--Portable Operating System Interface (POSIX)--Part 1: System Application Program Interface (API) [C Language], International Standard ISO/IEC 9945-1:1990 (IEEE Std 1003.1-1990)

POSIX.1a
P1003.1a--Draft Standard for Information Technology--Portable Operating System Interface (POSIX)--Part 1: System Application Program Interface (API) [C Language]--Amendment, P1003.1a, D12, January 1995, DS1933

POSIX.2
IEEE Standard for Information Technology---Portable Operating System Interface (POSIX)---Part 1: System Application Program Interface (API)---Amendment 1: Real-time Extension [C language] (IEEE Std 1003.b-1993, formerly known as IEEE P1003.4).

Path Name Rules for TPF File System C Functions

When using a TPF file system C function to perform an operation on an object, you identify the object by supplying its path. Following is a summary of rules to remember when specifying path names in a C function. The term object in these rules refers to any directory, file, link, or other object.

Specifying File Descriptors in System I/O C Functions

System-level I/O functions are used when an application program needs to work on a directory structure or when you need more control over a file than is provided by buffered I/O functions. System-level I/O functions such as creat, open, close, read, write, fcntl, chdir, chown, chmod, mkdir, mknod, stat, and others identify a file by specifying a file descriptor.

A file descriptor is a nonnegative integer that is first returned by the open or creat C function. Each open file has a unique file descriptor. Some TPF file system C functions use the file descriptor to identify an open file when performing operations on the file. File descriptors 0, 1, and 2 are initially reserved for the standard input (stdin), standard output (stdout), and standard error (stderr) streams.

Each file descriptor refers to an open file description, which contains information such as a file offset, status of the file, and access modes for the file. The same open file description can be referred to by more than one file descriptor, but a file descriptor can refer to only one open file description.

Figure 2. File Descriptor and Open File Description


Specifying Permissions in TPF File System C Functions

When using TPF file system C functions, you can restrict access to objects by using permissions. The types of permissions are read and write (for a file or a directory) or search (for a directory). The permissions are shown by a set of permission bits, which make up the mode of access of the file or directory. You can change the permission bits by using the chmod or fchmod change mode function. You can also use the umask function to control which file permission bits are set each time a job creates a file.