Clib Read From File Method
The Clib Read From File method reads data from an open file that you specify in the filePointer argument. It then stores this data in an argument, buffer, or BLOB that you specify. If this argument, buffer, or BLOB does not exist, then this method creates it. It returns one of the following values:
If successful, then it returns the number of elements it read.
If you specify the destBuffer argument, then it returns the number of bytes read, up to the value you specify in the bytelength argument.
If you specify the varDescription argument, then it returns one of the following values:
1 if it reads the data
0 if a read error occurs or if it encounters the end of file
Arguments
// Format A
Clib.fread(destBuffer, bytelength, filePointer)
// Format B
Clib.fread(destVar, varDescription, filePointer)
// Format C
Clib.fread(blobVar, blobDescriptor, filePointer)
The following table describes the arguments for the Clib Read From File method.
Argument | Description |
---|---|
destBuffer |
The buffer to contain the data that this method reads. |
bytelength |
The number of bytes that this method reads. |
filePointer |
A file pointer that the Clib Open File method returns. |
destVar |
A container to hold the data that this method reads. |
varDescription |
The format of the data that this method reads. For more information, see Clib Read From File Method. |
blobVar |
The BLOB where this method writes data. |
blobDescriptor |
The BLOB descriptor for the value you specify in the blobVar argument. |
Format of the Data That the Clib Read From File Method Reads
The following table describes the format of the data that the Clib Read From File method reads. You specify this format in the varDescription argument. If the destVar argument must hold a single datum, then you must set the varDescription argument to one of these formats. If the destVar contains blob data, then you must specify a blobdescriptor argument. A blobdescriptor can also consist of varDescriptions for the individual elements of the blobdescriptor.
Value | Description |
---|---|
UWORD8 |
Stored as an unsigned byte. |
SWORD8 |
Stored as a signed byte. |
UWORD16 |
Stored as an unsigned, 16-bit integer. |
SWORD16 |
Stored as a signed, 16-bit integer. |
UWORD24 |
Stored as an unsigned, 24-bit integer. |
SWORD24 |
Stored as a signed, 24-bit integer. |
UWORD32 |
Stored as an unsigned, 32-bit integer. |
SWORD32 |
Stored as a signed, 32-bit integer. |
FLOAT32 |
Stored as a floating-point number. |
FLOAT64 |
Stored as a double-precision, floating-point number. |
The following code includes example formats:
ClientDef = new blobDescriptor();
ClientDef.Sex = UWORD8;
ClientDef.MaritalStatus = UWORD8;
ClientDef._Unused1 = UWORD16;
ClientDef.FirstName = 30; ClientDef.LastName = 40;
ClientDef.Initial = UWORD8;
The Siebel eScript usage of fread differs from the standard C library usage in that the C library reads an array of numeric values or structures into consecutive bytes in memory. The Clib Read From File method reads data in the byte-order that the current value of the BigEndianMode global variable describes.
Example
The following example reads the following items from the fp file:
Reads the 16-bit i integer
Reads the 32-bit f float
Reads the 10-byte buffer from the buf buffer:
if ( !Clib.fread(i, SWORD16, fp) || !Clib.fread(f, FLOAT32, fp)
|| 10 != Clib.fread(buf, 10, fp) )
TheApplication().RaiseErrorText("Error reading from file.\n");
}