File Information

IDL maintains a file table in which it keeps a file descriptor for each file opened with IDL_FileOpen(). This table is indexed by the file Logical Unit Number, or LUN. These are the same LUNs IDL users use.

The IDL_FileStat() function is used to get information about a file.

IDL_FileStat()

void IDL_FileStat(int unit, IDL_FILE_STAT *stat_blk)

unit

The logical unit number (LUN) of the file unit to be checked. This function should only be called on file units that are known to be open.

stat_blk

A pointer to an IDL_FILE_STAT struct to be filled in with information about the file. The information returned is valid only as long as the file remains open. You must not access the fields of an IDL_FILE_STAT once the file it refers to has been closed. This struct has the definition:

typedef struct {

char *name;

short access;

IDL_SFILE_FLAGS_T flags;

FILE *fptr;

} IDL_FILE_STAT;

The fields of this struct are listed below:

name

A pointer to a null-terminated string containing the name the file was opened with.

access

A bit mask describing the access allowed to the file. The allowed bit values are:

flags

A bit mask that gives special information about the file. The defined bits are:

fptr

The stdio stream file pointer to the file. This field can be used with standard library functions to perform I/O. This field is always valid, although you shouldn’t use it if the file is an XDR file. You can check for this by looking for the IDL_F_XDR bit in the flags field.

If the file is not opened with the IDL_F_STDIO flag, fptr may be returned as an unusable NULL pointer, reflecting the fact that IDL is not using stdio to perform I/O on the file. If access to a valid fptr is important to your application, you should be sure to specify IDL_F_STDIO to the extra_flags argument to IDL_FileOpen, or use the STDIO keyword to OPEN if opening the file from the IDL user level.

In addition to the requirement to set the IDL_F_STDIO flag, note that IDL buffers I/O at a layer above the stdio package. If your code does I/O directly to a file that is also being written to from the IDL user level, the IDL buffer may cause data to be written to the file in a different order than you expect. There are several approaches you can take to prevent this: