Bookshelf Home | Contents | Index | Search | PDF |
Siebel eScript Language Reference > Siebel eScript Commands > The Clib Object >
Clib.fread() Method
This method reads data from an open file and stores it in a variable.
Syntax A
Clib.fread(destBuffer, bytelength, filePointer)
Syntax B
Clib.fread(destVar, varDescription, filePointer)
Syntax C
Clib.fread(blobVar, blobDescriptor, filePointer)
Returns
The number of elements read. For destBuffer, the number of bytes read, up to bytelength. For varDescription, 1 if the data is read, or 0 if there is a read error or EOF is encountered.
Usage
This method reads data from the open file filePointer and stores it in the specified variable. If it does not yet exist, the variable, buffer, or BLOB is created. The varDescription value is a variable that describes how and how much data is to be read: if destVar is to hold a single datum, then varDescription must be one of the following:
For example, the definition of a structure might be:
ClientDef = new blobDescriptor();
ClientDef.Sex = UWORD8;
ClientDef.MaritalStatus = UWORD8;
ClientDef._Unused1 = UWORD16;
ClientDef.FirstName = 30; ClientDef.LastName = 40;
ClientDef.Initial = UWORD8;The Siebel eScript version of fread() differs from the standard C version in that the standard C library is set up for reading arrays of numeric values or structures into consecutive bytes in memory. In JavaScript, this is not necessarily the case.
Data types are read from the file in a byte-order described by the current value of the BigEndianMode global variable.
Example
To read the 16-bit integer
i
, the 32-bit floatf
, and then the 10-byte bufferbuf
from the open filefp
, use code like this:if ( !Clib.fread(i, SWORD16, fp) || !Clib.fread(f, FLOAT32, fp)
|| 10 != Clib.fread(buf, 10, fp) )
TheApplication().RaiseErrorText("Error reading from file.\n");
}See Also
Bookshelf Home | Contents | Index | Search | PDF |
Siebel eScript Language Reference Published: 18 April 2003 |