Jump to content

DosProtectSetFilePtrL: Difference between revisions

From EDM2
Created page with "==Description== DosProtectSetFilePtrL moves the read or write pointer according to the type of move specified. ==Syntax== <PRE> #define INCL DOSFILEMGR #include os2.h ..."
 
Ak120 (talk | contribs)
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Description==
DosProtectSetFilePtrL moves the read or write pointer according to the type of move specified.
DosProtectSetFilePtrL moves the read or write pointer according to the type of move specified.  


==Syntax==
==Syntax==
<PRE>
  DosProtectSetFilePtrL (hFile, ib, method, ibActual, fhFileHandleLockID)
#define INCL DOSFILEMGR
#include os2.h


    APIRET DosProtectSetFilePtrL
        (HFILE hFile, LONGLONG ib, ULONG method, PLONGLONG ibActual, FHLOCK fhFileHandleLockID)
</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 (LONG) input : The method of moving.
:This field specifies the location in the file at which the read/write pointer starts before adding the ib offset. The values and their meanings are as shown 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.
;fhFileHandleLockID (FHLOCK) input: The filehandle lockid returned by a previous DosProtectOpenL.


; ib LONGLONG) input : The signed distance (offset) to move, in bytes.
; method LONG) input : The method of moving.
This field specifies the location in the file at which the read/write pointer starts before adding the ib offset. The values and their meanings are as shown 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.
; fhFileHandleLockID FHLOCK) input : The filehandle lockid returned by a previous DosProtectOpenL.
==Return Code==
==Return Code==
ulrc APIRET) returns
;ulrc APIRET) returns:DosProtectSetFilePtrL returns one of the following values:
 
* 0 NO_ERROR
DosProtectSetFilePtrL returns one of the following values
* ERROR_INVALID_FUNCTION
 
* ERROR_INVALID_HANDLE
*           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. DosProtectSetFilePtrL 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. DosProtectSetFilePtrL cannot be used to move to a negative position in the file.


DosProtectSetFilePtrL cannot be used for a character device or pipe.  
DosProtectSetFilePtrL cannot be used for a character device or pipe.


==Example Code==
==Example Code==
This example opens or creates and opens a file named DOSPROT.DAT , writes a string to it, returns the file pointer to the beginning of the file, reads it, and finally closes it using DosProtect functions.
This example opens or creates and opens a file named DOSPROT.DAT, writes a string to it, returns the file pointer to the beginning of the file, reads it, and finally closes it using DosProtect functions.
 
<PRE>
<PRE>
#define INCL_DOSFILEMGR         /* File Manager values */#define INCL_DOSERRORS           /* DOS Error values    */
#define INCL_DOSFILEMGR       /* File Manager values */
#include os2.h  
#define INCL_DOSERRORS         /* DOS Error values    */
#include stdio.h  
#include <os2.h>
#include string.h  
#include <stdio.h>
#include <string.h>


int main(VOID)
int main(VOID){
HFILE  hfFileHandle  = 0L;
  HFILE  hfFileHandle  = 0L;
ULONG  ulAction      = 0;
  ULONG  ulAction      = 0;
ULONG  ulBytesRead    = 0;
  ULONG  ulBytesRead    = 0;
ULONG  ulWrote        = 0;
  ULONG  ulWrote        = 0;
LONGLONG  ullLocal    = 0;
  LONGLONG  ullLocal    = 0;
UCHAR  uchFileName 20  = "dosprot.dat",
  UCHAR  uchFileName 20  = "dosprot.dat",
uchFileData 100  = " ";
        uchFileData 100  = " ";
FHLOCK FileHandleLock = 0;        /* File handle lock  */
  FHLOCK FileHandleLock = 0;        /* File handle lock  */
APIRET rc            = NO_ERROR; /* Return code */
  APIRET rc            = NO_ERROR; /* Return code */


/* Open the file test.dat.  Make it read/write, open it */
/* Open the file test.dat.  Make it read/write, open it */
/* if it already exists and create it if it is new.    */
/* if it already exists and create it if it is new.    */
rc = DosProtectOpenL(uchFileName,            /* File path name          */
  rc = DosProtectOpenL(uchFileName,            /* File path name          */
hfFileHandle,                  /* File handle            */
                hfFileHandle,                  /* File handle            */
ulAction,                      /* Action taken            */
                ulAction,                      /* Action taken            */
(LONGLONG)100,                          /* File primary allocation */
      (LONGLONG)100,                          /* File primary allocation */
FILE_ARCHIVED | FILE_NORMAL,    /* File attribute          */
                FILE_ARCHIVED | FILE_NORMAL,    /* File attribute          */
OPEN_ACTION_CREATE_IF_NEW |
                OPEN_ACTION_CREATE_IF_NEW |
OPEN_ACTION_OPEN_IF_EXISTS,    /* Open function type      */
                OPEN_ACTION_OPEN_IF_EXISTS,    /* Open function type      */
OPEN_FLAGS_NOINHERIT |
                OPEN_FLAGS_NOINHERIT |
OPEN_SHARE_DENYNONE  |
                OPEN_SHARE_DENYNONE  |
OPEN_ACCESS_READWRITE,          /* Open mode of the file  */
                OPEN_ACCESS_READWRITE,          /* Open mode of the file  */
0L,                            /* No extended attribute  */
                0L,                            /* No extended attribute  */
FileHandleLock);              /* File handle lock id    */
                FileHandleLock);              /* File handle lock id    */
if (rc != NO_ERROR)
  if (rc != NO_ERROR){
printf("DosProtectOpenL error  return code = %u\n", rc);
    printf("DosProtectOpenL error  return code = %u\n", rc);
return 1;
    return 1;
   else
   } else {
printf ("DosProtectOpenL  Action taken = %u\n", ulAction);
    printf ("DosProtectOpenL  Action taken = %u\n", ulAction);
   /* endif */
   } /* endif */


/* Write a string to the file */
/* Write a string to the file */
strcpy (uchFileData, "testing...\n3...\n2...\n1\n");
  strcpy (uchFileData, "testing...\n3...\n2...\n1\n");
 
rc = DosProtectWrite (hfFileHandle,      /* File handle                  */
(PVOID) uchFileData,      /* String to be written        */
sizeof (uchFileData),      /* Size of string to be written */
ulWrote,                  /* Bytes actually written      */
FileHandleLock);          /* File handle lock id          */if (rc != NO_ERROR)


printf("DosProtectWrite error  return code = %u\n", rc);
  rc = DosProtectWrite (hfFileHandle,      /* File handle                  */
return 1;
                (PVOID) uchFileData,      /* String to be written        */
   else
                sizeof (uchFileData),      /* Size of string to be written */
printf ("DosProtectWrite  Bytes written = %u\n", ulWrote);
                  ulWrote,                  /* Bytes actually written      */
   /* endif */
                FileHandleLock);          /* File handle lock id          */
  if (rc != NO_ERROR) {
    printf("DosProtectWrite error  return code = %u\n", rc);
    return 1;
   } else {
    printf ("DosProtectWrite  Bytes written = %u\n", ulWrote);
   } /* endif */


/* Move the file pointer back to the beginning of the file */
/* Move the file pointer back to the beginning of the file */
rc = DosProtectSetFilePtrL (hfFileHandle,  /* File Handle          */
  rc = DosProtectSetFilePtrL (hfFileHandle,  /* File Handle          */
(LONGLONG)0,            /* Offset              */
                      (LONGLONG)0,            /* Offset              */
FILE_BEGIN,            /* Move from BOF        */
                      FILE_BEGIN,            /* Move from BOF        */
ullLocal,              /* New location address */
                      ullLocal,              /* New location address */
FileHandleLock);        /* File handle lock id  */
                      FileHandleLock);        /* File handle lock id  */
if (rc != NO_ERROR)
  if (rc != NO_ERROR) {
printf("DosSetFilePtr error  return code = %u\n", rc);
    printf("DosSetFilePtr error  return code = %u\n", rc);
return 1;
    return 1;
   
   


/* Read the first 100 bytes of the file */
  /* Read the first 100 bytes of the file */
rc = DosProtectRead (hfFileHandle,        /* File Handle                */
  rc = DosProtectRead (hfFileHandle,        /* File Handle                */
uchFileData,                /* String to be read          */
                uchFileData,                /* String to be read          */
100L,                        /* Length of string to be read */
                100L,                        /* Length of string to be read */
ulBytesRead,                /* Bytes actually read        */
                  ulBytesRead,                /* Bytes actually read        */
FileHandleLock);            /* File handle lock id        */
                FileHandleLock);            /* File handle lock id        */
if (rc != NO_ERROR)
  if (rc != NO_ERROR) {
printf("DosProtectRead error  return code = %u\n", rc);
    printf("DosProtectRead error  return code = %u\n", rc);
return 1;
    return 1;
   else
   } else {
printf("DosProtectRead  Bytes read = %u\n%s\n", ulBytesRead, uchFileData);
    printf("DosProtectRead  Bytes read = %u\n%s\n", ulBytesRead, uchFileData);
   /* endif */
   } /* endif */


rc = DosProtectClose(hfFileHandle, FileHandleLock);  /* Close the file */
  rc = DosProtectClose(hfFileHandle, FileHandleLock);  /* Close the file */
if (rc != NO_ERROR)
  if (rc != NO_ERROR) {
printf("DosProtectClose error  return code = %u\n", rc);
    printf("DosProtectClose error  return code = %u\n", rc);
return 1;
    return 1;
  }
return NO_ERROR;
  return NO_ERROR;
}
</PRE>


</PRE>
==Related Functions==
==Related Functions==
* [[OS2 API:CPI:DosProtectOpenL|CPI:DosProtectOpenL]]
*[[DosProtectOpenL]]
* [[OS2 API:CPI:DosProtectRead|CPI:DosProtectRead]]
*[[DosProtectRead]]
* [[OS2 API:CPI:DosProtectSetFileSizeL|CPI:DosProtectSetFileSizeL]]
*[[DosProtectSetFileSizeL]]
* [[OS2 API:CPI:DosProtectWrite|CPI:DosProtectWrite]]
*[[DosProtectWrite]]


[[Category:The OS/2 API Project]]
[[Category:Dos]]

Latest revision as of 03:55, 1 December 2019

DosProtectSetFilePtrL moves the read or write pointer according to the type of move specified.

Syntax

DosProtectSetFilePtrL (hFile, ib, method, ibActual, fhFileHandleLockID)

Parameters

hFile (HFILE) input
The handle returned by a previous DosOpenL function.
ib (LONGLONG) input
The signed distance (offset) to move, in bytes.
method (LONG) input
The method of moving.
This field specifies the location in the file at which the read/write pointer starts before adding the ib offset. The values and their meanings are as shown 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.
fhFileHandleLockID (FHLOCK) input
The filehandle lockid returned by a previous DosProtectOpenL.

Return Code

ulrc APIRET) returns
DosProtectSetFilePtrL returns one of the following values:
  • 0 NO_ERROR
  • ERROR_INVALID_FUNCTION
  • ERROR_INVALID_HANDLE
  • 132 ERROR_SEEK_ON_DEVICE
  • 131 ERROR_NEGATIVE_SEEK
  • 130 ERROR_DIRECT_ACCESS_HANDLE

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. DosProtectSetFilePtrL cannot be used to move to a negative position in the file.

DosProtectSetFilePtrL cannot be used for a character device or pipe.

Example Code

This example opens or creates and opens a file named DOSPROT.DAT, writes a string to it, returns the file pointer to the beginning of the file, reads it, and finally closes it using DosProtect functions.

#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;
  ULONG  ulAction       = 0;
  ULONG  ulBytesRead    = 0;
  ULONG  ulWrote        = 0;
  LONGLONG  ullLocal    = 0;
  UCHAR  uchFileName 20   = "dosprot.dat",
         uchFileData 100  = " ";
  FHLOCK FileHandleLock = 0;        /* File handle lock   */
  APIRET rc             = NO_ERROR; /* Return code */

/* Open the file test.dat.  Make it read/write, open it */
/* if it already exists and create it if it is new.     */
  rc = DosProtectOpenL(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   */
                 FileHandleLock);               /* File handle lock id     */
  if (rc != NO_ERROR){
    printf("DosProtectOpenL error  return code = %u\n", rc);
    return 1;
  } else {
    printf ("DosProtectOpenL  Action taken = %u\n", ulAction);
  } /* endif */

/* Write a string to the file */
  strcpy (uchFileData, "testing...\n3...\n2...\n1\n");

  rc = DosProtectWrite (hfFileHandle,       /* File handle                  */
                 (PVOID) uchFileData,       /* String to be written         */
                 sizeof (uchFileData),      /* Size of string to be written */
                  ulWrote,                  /* Bytes actually written       */
                 FileHandleLock);           /* File handle lock id          */
  if (rc != NO_ERROR) {
    printf("DosProtectWrite error  return code = %u\n", rc);
    return 1;
  } else {
    printf ("DosProtectWrite  Bytes written = %u\n", ulWrote);
  } /* endif */

/* Move the file pointer back to the beginning of the file */
  rc = DosProtectSetFilePtrL (hfFileHandle,   /* File Handle          */
                      (LONGLONG)0,            /* Offset               */
                      FILE_BEGIN,             /* Move from BOF        */
                       ullLocal,              /* New location address */
                      FileHandleLock);        /* File handle lock id  */
  if (rc != NO_ERROR) {
    printf("DosSetFilePtr error  return code = %u\n", rc);
    return 1;
 

  /* Read the first 100 bytes of the file */
   rc = DosProtectRead (hfFileHandle,         /* File Handle                 */
                 uchFileData,                 /* String to be read           */
                 100L,                        /* Length of string to be read */
                  ulBytesRead,                /* Bytes actually read         */
                 FileHandleLock);             /* File handle lock id         */
  if (rc != NO_ERROR) {
    printf("DosProtectRead error  return code = %u\n", rc);
    return 1;
  } else {
    printf("DosProtectRead  Bytes read = %u\n%s\n", ulBytesRead, uchFileData);
  } /* endif */

  rc = DosProtectClose(hfFileHandle, FileHandleLock);   /* Close the file */
  if (rc != NO_ERROR) {
    printf("DosProtectClose error  return code = %u\n", rc);
    return 1;
  }
  return NO_ERROR;
}

Related Functions