Example #1
0
int main(VOID) {

   HFILE  hfFileHandle   = 0L;     /* Handle for file being manipulated */

   ULONG  ulAction       = 0;      /* Action taken by DosOpen */

   FHLOCK FileHandleLock = 0;      /* File handle lock   */



   ULONG  ulWrote        = 0;      /* Number of bytes written by DosWrite */

   UCHAR  uchFileName[20]  = "dospman.dat",     /* Name of file */

          uchFileData[4]   = "DATA";            /* Data to write to file */

   APIRET rc             = NO_ERROR;            /* Return code */



   /* Open the file dosman.dat.  Use an existing file or create a new */

   /* one if it doesn't exist.                                      */

   rc = DosProtectOpen(uchFileName, &hfFileHandle, &ulAction, 4L,

              FILE_ARCHIVED | FILE_NORMAL,

              OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,

              OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE  |

              OPEN_ACCESS_READWRITE, 0L, &FileHandleLock);

   if (rc != NO_ERROR) {

      printf("DosOpen error: return code = %u\n", rc);

      return 1;

   }



   rc = DosProtectWrite (hfFileHandle, (PVOID) uchFileData,

                  sizeof (uchFileData), &ulWrote, FileHandleLock);

   if (rc != NO_ERROR) {

      printf("DosWrite error: return code = %u\n", rc);

      return 1;

   }



   rc = DosResetBuffer (hfFileHandle);

   if (rc != NO_ERROR) {

      printf("DosResetBuffer error: return code = %u\n", rc);

      return 1;

   } /* endif */



   rc = DosProtectSetFileSize (hfFileHandle, 8L, FileHandleLock);

   if (rc != NO_ERROR) {

      printf("DosSetFileSize error: return code = %u\n", rc);

      return 1;

   }



   return NO_ERROR;

}
Example #2
0
 int main(VOID) {



 UCHAR       uchFileName[]   = "DOSFDEL.DAT";   /* File we want to delete    */

 HFILE       fhDelFile       = 0;               /* File handle from DosOpen  */

 FILESTATUS3 fsts3FileInfo   = {{0}};  /* Information associated with file   */

 ULONG       ulBufferSize    = sizeof(FILESTATUS3); /* File info buffer size */

 ULONG       ulOpenAction    = 0;                 /* Action taken by DosOpen */

 APIRET      rc              = NO_ERROR;          /* Return code             */

 FHLOCK      FHLock          = 0;                 /* File handle lock        */



                 /* Create a read-only file */



  rc = DosProtectOpen(uchFileName, &fhDelFile,

               &ulOpenAction, 10L, FILE_READONLY,

               OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,

               OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, 0L, &FHLock);

  if (rc != NO_ERROR) {

     printf("DosProtectOpen error: return code = %u\n", rc);

     return 1;

  }



  rc = DosProtectQueryFileInfo(fhDelFile, FIL_STANDARD,

               &fsts3FileInfo, ulBufferSize, FHLock);   /* Get standard info */

  if (rc != NO_ERROR) {

      printf("DosProtectQueryFileInfo error: return code = %u\n", rc);

      return 1;

  } else { printf("File %s created read-only.\n",uchFileName); }



    /*   Change the file attributes to be "normal"  */



    fsts3FileInfo.attrFile  = FILE_NORMAL;

    rc = DosProtectSetFileInfo(fhDelFile, FIL_STANDARD,

                        &fsts3FileInfo, ulBufferSize, FHLock);

    if (rc != NO_ERROR) {

        printf("DosProtectSetFileInfo error: return code = %u\n", rc);

        return 1;

    }



    rc = DosProtectClose(fhDelFile, FHLock);

    /* Should verify that (rc != NO_ERROR) here... */



           /* Delete the file */



    rc = DosForceDelete(uchFileName);

    if (rc != NO_ERROR) {

        printf("DosForceDelete error: return code = %u\n", rc);

        return 1;

    } else {

        printf("File %s has been deleted.\n",uchFileName);

    }  /* endif */



   return NO_ERROR;

}