ReadVData
Read variable-length data record.
Short Name
RDVREC()
Type
Low-Level variable-length record function
Declaration
COUNT ReadVData(FILNO datno, LONG recbyt, pVOID recptr, VRLEN varlen)
Description
ReadVData() reads the variable-length data record at byte position recbyt for data file datno into the buffer area pointed to by recptr. If varlen, the size of the buffer pointed to by recptr, is not large enough for the variable-length record, ReadVData() returns an error.
To ensure varlen is large enough, call VDataLength() before calling ReadVData(). VDataLength() returns the actual length of the record. If the existing buffer is not large enough, a new, larger buffer must be allocated before calling ReadVData().
Note: No check is actually made to be sure that the region pointed to by recptr is in fact as large as varlen indicates. It is up to the application to ensure that varlen accurately specifies the size of the area pointed to by recptr.
Return
Value |
Symbolic Constant |
Explanation |
---|---|---|
0 |
NO_ERROR |
Successful read. |
29 |
ZREC_ERR |
Attempt to read at byte offset zero. |
33 |
DNUL_ERR |
recptr is NULL. |
35 |
SEEK_ERR |
lseek() failed while preparing for read. |
36 |
READ_ERR |
Operating system could not execute read. |
48 |
FMOD_ERR |
datno is not assigned to a variable-length data file. |
123 |
RVHD_ERR |
Record is not preceded by a valid record mark. |
153 |
VBSZ_ERR |
varlen < actual record length. |
154 |
VRCL_ERR |
Variable-length record is zero bytes long. |
158 |
VFLG_ERR |
Variable-length record is not marked as active. |
160 |
ITIM_ERR |
Multi-user interference: key value changed between index search and subsequent data record read. |
See c-tree Error Codes for a complete listing of valid c-tree error values.
Example
FILNO datno, keyno;
VRLEN cur_bufsiz, varlen;
pTEXT recptr, calloc();
LONG part_number, pntr;
scanf("%ld",&part_number);
if ((pntr = GetKey(keyno,&part_number)) != DRNZERO) {
varlen = VDataLength(datno,pntr);
if (varlen > cur_bufsiz) {
free(recptr);
recptr = calloc(1,varlen));
cur_bufsiz = varlen;
}
if (ReadVData(datno,pntr,recptr,varlen))
printf>("\nError #%d reading at %ld", uerr_cod, pntr);
}
Limitations
The recbyt parameter in this function is a 4-byte value capable of addressing at most 4 gigabytes. If your application supports HUGE files (greater than 4 gigabytes), you must use the ctSETHGH() and ctGETHGH() functions to set or get the high-order 4 bytes of the file offset. See also Record Offsets Under Huge File Support.
See also
ctSETHGH(), ctGETHGH(), ReReadVRecord(), VDataLength(), WriteVData()