|
|
(4 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| ==Description==
| |
| DosSetFilePtrL moves the read write pointer according to the type of move specified. | | DosSetFilePtrL moves the read write pointer according to the type of move specified. |
|
| |
|
| ==Syntax== | | ==Syntax== |
| <PRE>
| | DosSetFilePtrL (hFile, ib, method, ibActual) |
| #define INCL DOSFILEMGR
| |
| #include os2.h
| |
|
| |
|
| APIRET DosSetFilePtrL
| |
| (HFILE hFile, LONGLONG ib, ULONG method, PLONGLONG ibActual)
| |
| </PRE>
| |
| ==Parameters== | | ==Parameters== |
| ; hFile HFILE) input : The handle returned by a previous DosOpenL function. | | ;hFile ([[HFILE]]) input : The handle returned by a previous [[DosOpenL]] function. |
| | ;ib ([[LONGLONG]]) input : The signed distance (offset) to move, in bytes. |
| | ;method ([[ULONG]]) input : The method of moving. |
| | :Specifies a location in the file from where the ib to move the read/write pointer starts. The values and their meanings are described in the following list: |
| | :*FILE_BEGIN - Move the pointer from the beginning of the file. |
| | :*FILE_CURRENT - Move the pointer from the current location of the read write pointer. |
| | :*FILE_END - Move the pointer from the end of the file. Use this method to determine a file s size. |
| | ; ibActual (PLONGLONG) output : Address of the new pointer location. |
|
| |
|
| ; ib LONGLONG) input : The signed distance (offset) to move, in bytes.
| |
|
| |
| ; method ULONG) input : The method of moving.
| |
|
| |
| Specifies a location in the file from where the ib to move the read/write pointer starts. The values and their meanings are described in the following list
| |
|
| |
| FILE_BEGIN
| |
| Move the pointer from the beginning of the file.
| |
|
| |
| FILE_CURRENT
| |
| Move the pointer from the current location of the read write pointer.
| |
|
| |
| FILE_END
| |
| Move the pointer from the end of the file. Use this method to determine a file s size.
| |
|
| |
| ; ibActual PLONGLONG) output : Address of the new pointer location.
| |
| ==Return Code== | | ==Return Code== |
| ulrc APIRET) returns
| | ;ulrc ([[APIRET]]) returns:DosSetFilePtrL returns one of the following values: |
| | | * 0 NO_ERROR |
| DosSetFilePtrL returns one of the following values | | * 1 ERROR_INVALID_FUNCTION |
| | | * 6 ERROR_INVALID_HANDLE |
| * 0 NO_ERROR | | *132 ERROR_SEEK_ON_DEVICE |
| * ERROR_INVALID_FUNCTION | | *131 ERROR_NEGATIVE_SEEK |
| * ERROR_INVALID_HANDLE | | *130 ERROR_DIRECT_ACCESS_HANDLE |
| * 132 ERROR_SEEK_ON_DEVICE | |
| * 131 ERROR_NEGATIVE_SEEK | |
| * 130 ERROR_DIRECT_ACCESS_HANDLE | |
|
| |
|
| ==Remarks== | | ==Remarks== |
| The read/write pointer in a file is a signed 64-bit number. A negative value for ib moves the pointer backward in the file; a positive value moves it forward. DosSetFilePtrL cannot be used to move to a negative position in the file. | | The read/write pointer in a file is a signed 64-bit number. A negative value for ib moves the pointer backward in the file; a positive value moves it forward. ''DosSetFilePtrL'' cannot be used to move to a negative position in the file. |
| | |
| DosSetFilePtrL cannot be used for a character device or pipe.
| |
| | |
| ==Example Code==
| |
| This example opens or creates and opens a file named DOSTEST.DAT , writes to it, positions the file pointer back to the beginning of the file, reads from the file, and finally closes it.
| |
| <PRE>
| |
| #define INCL_DOSFILEMGR /* File Manager values */#define INCL_DOSERRORS /* DOS Error values */
| |
| #include os2.h
| |
| #include stdio.h
| |
| #include string.h
| |
| | |
| int main(void)
| |
| HFILE hfFileHandle = 0L; /* Handle for file being manipulated */
| |
| ULONG ulAction = 0; /* Action taken by DosOpenL */
| |
| ULONG ulBytesRead = 0; /* Number of bytes read by DosRead */
| |
| ULONG ulWrote = 0; /* Number of bytes written by DosWrite */
| |
| LONGLONG ullLocal = 0; /* File pointer position after DosSetFilePtr */
| |
| UCHAR uchFileName 20 = "dostest.dat", /* Name of file */
| |
| uchFileData 100 = " "; /* Data to write to file */
| |
| APIRET rc = NO_ERROR; /* Return code */
| |
| | |
| /* Open the file test.dat. Use an existing file or create a new */
| |
| /* one if it doesn't exist. */
| |
| rc = DosOpenL(uchFileName, /* File path name */
| |
| hfFileHandle, /* File handle */
| |
| ulAction, /* Action taken */
| |
| (LONGLONG)100, /* File primary allocation */
| |
| FILE_ARCHIVED | FILE_NORMAL, /* File attribute */
| |
| OPEN_ACTION_CREATE_IF_NEW |
| |
| OPEN_ACTION_OPEN_IF_EXISTS, /* Open function type */
| |
| OPEN_FLAGS_NOINHERIT |
| |
| OPEN_SHARE_DENYNONE |
| |
| OPEN_ACCESS_READWRITE, /* Open mode of the file */
| |
| 0L); /* No extended attribute */if (rc != NO_ERROR)
| |
| | |
| printf("DosOpenL error return code = %u\n", rc);
| |
| return 1;
| |
| else
| |
| printf ("DosOpenL Action taken = %ld\n", ulAction);
| |
| /* endif */
| |
| | |
| /* Write a string to the file */
| |
| strcpy (uchFileData, "testing...\n1...\n2...\n3\n");
| |
| | |
| rc = DosWrite (hfFileHandle, /* File handle */
| |
| (PVOID) uchFileData, /* String to be written */
| |
| sizeof (uchFileData), /* Size of string to be written */
| |
| ulWrote); /* Bytes actually written */
| |
| | |
| if (rc != NO_ERROR)
| |
| printf("DosWrite error return code = %u\n", rc);
| |
| return 1;
| |
| else
| |
| printf ("DosWrite Bytes written = %u\n", ulWrote);
| |
| /* endif */
| |
| | |
| /* Move the file pointer back to the beginning of the file */
| |
| rc = DosSetFilePtrL (hfFileHandle, /* File Handle */
| |
| (LONGLONG)0, /* Offset */
| |
| FILE_BEGIN, /* Move from BOF */
| |
| ullLocal); /* New location address */
| |
| if (rc != NO_ERROR)
| |
| printf("DosSetFilePtrL error return code = %u\n", rc);
| |
| return 1;
| |
|
| |
| | |
| /* Read the first 100 bytes of the file */
| |
| rc = DosRead (hfFileHandle, /* File Handle */
| |
| uchFileData, /* String to be read */
| |
| 100L, /* Length of string to be read */
| |
| ulBytesRead); /* Bytes actually read */
| |
| | |
| if (rc != NO_ERROR)
| |
| printf("DosRead error return code = %u\n", rc);
| |
| return 1;
| |
| else
| |
| printf ("DosRead Bytes read = %u\n%s\n", ulBytesRead, uchFileData);
| |
| /* endif */
| |
| | |
| rc = DosClose(hfFileHandle); /* Close the file */
| |
| | |
| if (rc != NO_ERROR)
| |
| printf("DosClose error return code = %u\n", rc);
| |
| return 1;
| |
|
| |
| return NO_ERROR;
| |
|
| |
|
| |
|
| </PRE>
| | ''DosSetFilePtrL'' cannot be used for a character device or pipe. |
|
| |
|
| ==Related Functions== | | ==Related Functions== |
| * [[OS2 API:CPI:DosOpenL|DosOpenL]] | | * [[DosOpenL]] |
| * [[OS2 API:CPI:DosRead|DosRead]] | | * [[DosRead]] |
| * [[OS2 API:CPI:DosSetFileSizeL|DosSetFileSizeL]] | | * [[DosSetFileSizeL]] |
| * [[OS2 API:CPI:DosWrite|DosWrite]] | | * [[DosWrite]] |
|
| |
|
| [[Category:The OS/2 API Project]] | | [[Category:Dos]] |
DosSetFilePtrL moves the read write pointer according to the type of move specified.
Syntax
DosSetFilePtrL (hFile, ib, method, ibActual)
Parameters
- hFile (HFILE) input
- The handle returned by a previous DosOpenL function.
- ib (LONGLONG) input
- The signed distance (offset) to move, in bytes.
- method (ULONG) input
- The method of moving.
- Specifies a location in the file from where the ib to move the read/write pointer starts. The values and their meanings are described in the following list:
- FILE_BEGIN - Move the pointer from the beginning of the file.
- FILE_CURRENT - Move the pointer from the current location of the read write pointer.
- FILE_END - Move the pointer from the end of the file. Use this method to determine a file s size.
- ibActual (PLONGLONG) output
- Address of the new pointer location.
Return Code
- ulrc (APIRET) returns
- DosSetFilePtrL returns one of the following values:
- 0 NO_ERROR
- 1 ERROR_INVALID_FUNCTION
- 6 ERROR_INVALID_HANDLE
- 132 ERROR_SEEK_ON_DEVICE
- 131 ERROR_NEGATIVE_SEEK
- 130 ERROR_DIRECT_ACCESS_HANDLE
The read/write pointer in a file is a signed 64-bit number. A negative value for ib moves the pointer backward in the file; a positive value moves it forward. DosSetFilePtrL cannot be used to move to a negative position in the file.
DosSetFilePtrL cannot be used for a character device or pipe.
Related Functions