File descriptor

When using ILE C/400® stream I/O functions as defined by the American National Standards Institute (ANSI) to perform operations on a file, you identify the file through use of pointers. When using the integrated file system C functions, you identify the file by specifying a file descriptor. A file descriptor is a positive integer that must be unique in each job.

The job uses a file descriptor to identify an open file when performing operations on the file. The file descriptor is represented by the variable fildes in C functions that operate on the integrated file system and by the variable descriptor in C functions that operate on sockets.

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 1. File descriptor and open file description
File descriptor and open file description

If an ILE C/400 stream I/O function is used with the integrated file system, the ILE C/400 run-time support converts the file pointer to a file descriptor.

When using the "root" (/), QOpenSys, or user-defined file systems, you can pass access to an open file description from one job to another, thus allowing the job to access the file. You do this by using the givedescriptor() or takedescriptor() function to pass the file descriptor between jobs.

Related information
givedescriptor() API
takedescriptor() API
Sockets programming
Sockets APIs