PRB: _lseek() Fails on Different Offset ValuesLast reviewed: August 8, 1997Article ID: Q135326 |
The information in this article applies to:
SYMPTOMSThe Run-Time function _lseek() fails on different offset values (number of bytes from origin). For example, in the following sample code, _lseek() fails if it seeks to the offset positions 0x1ffff, 0x2ffff, 0x3ffff and so on in a file.
CAUSEThis behavior occurs when you fail to include the required header file IO.H. This header file contains the prototype for the _lseek() function.
RESOLUTIONInclude the header file.
STATUSThis behavior is by design.
MORE INFORMATIONIf the code is compiled with warning level 3 or higher, the compiler will indicate that the function is not defined. It is a good idea to compile all code with a high warning level to prevent problems like this from happening.
Sample Code to Reproduce Behavior
/* Compile options needed: None */ #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <sys\types.h> #include <sys\stat.h> // #include <io.h> // Uncomment this line to fix the problem void main() { int File; long temp; if ((File = _open("test.dat", O_RDWR | O_BINARY, S_IWRITE)) == -1 ){ printf("File open error \n"); exit(1); } temp = 0x0001fffeL; // This read works if (_lseek(File, temp, SEEK_SET) == -1L) printf("Error reading from position: %lx\n", temp); else printf("Read OK from position: %lx\n",temp); temp = 0x0001ffffL; // This read fails if (_lseek(File, temp, SEEK_SET) == -1L) printf("Error reading from position: %lx\n", temp); else printf("Read OK from position: %lx\n",temp); _close(File); } |
Additional query words: 8.00 8.00c lseek
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |