Jump to content

DosSetFileSizeL: Difference between revisions

From EDM2
Created page with "==Description== DosSetFileSizeL changes the size of a file. ==Syntax== <PRE> #define INCL DOSFILEMGR #include os2.h APIRET DosSetFileSizeL (HFILE hFile, LONGL..."
 
Ak120 (talk | contribs)
mNo edit summary
Line 7: Line 7:
#include  os2.h  
#include  os2.h  


    APIRET DosSetFileSizeL
APIRET DosSetFileSizeL (HFILE hFile, LONGLONG cbSize)
        (HFILE hFile, LONGLONG cbSize)
</PRE>
</PRE>
==Parameters==
==Parameters==
; hFile HFILE) input : The handle of the file whose size to be changed.  
; hFile HFILE) input : The handle of the file whose size to be changed.
; cbSize LONGLONG) input : The new size, in bytes, of the file.


; cbSize LONGLONG) input : The new size, in bytes, of the file.
==Return Code==
==Return Code==
  ulrc APIRET) returns
  ulrc APIRET) returns


DosSetFileSizeL returns one of the following values
DosSetFileSizeL returns one of the following values:
 
* 0 NO_ERROR
* 0         NO_ERROR
*   ERROR_ACCESS_DENIED
*           ERROR_ACCESS_DENIED
*   ERROR_INVALID_HANDLE
*           ERROR_INVALID_HANDLE
* 26 ERROR_NOT_DOS_DISK  
* 26       ERROR_NOT_DOS_DISK  
* 33 ERROR_LOCK_VIOLATION  
* 33       ERROR_LOCK_VIOLATION  
* 87 ERROR_INVALID_PARAMETER  
* 87       ERROR_INVALID_PARAMETER  
* 112 ERROR_DISK_FULL
* 112       ERROR_DISK_FULL


==Remarks==
==Remarks==
Line 33: Line 32:


==Example Code==
==Example Code==
This example writes to a file named DOSMAN.DAT , resets the buffer, and changes the file size.
This example writes to a file named DOSMAN.DAT, resets the buffer, and changes the file size.
 
<PRE>
<PRE>
#define INCL_DOSFILEMGR          /* File Manager values */#define INCL_DOSERRORS          /* DOS Error values    */
#define INCL_DOSFILEMGR          /* File Manager values */
#define INCL_DOSERRORS          /* DOS Error values    */
#include  os2.h  
#include  os2.h  
#include  stdio.h  
#include  stdio.h  
Line 45: Line 44:
ULONG  ulAction      = 0;      /* Action taken by DosOpenL */
ULONG  ulAction      = 0;      /* Action taken by DosOpenL */
ULONG  ulWrote        = 0;      /* Number of bytes written by DosWrite */
ULONG  ulWrote        = 0;      /* Number of bytes written by DosWrite */
UCHAR  uchFileName 20   = "dosman.dat",    /* Name of file */
UCHAR  uchFileName 20 = "dosman.dat",    /* Name of file */
uchFileData 4    = "DATA";            /* Data to write to file */
uchFileData 4    = "DATA";            /* Data to write to file */
APIRET rc            = NO_ERROR;            /* Return code */
APIRET rc            = NO_ERROR;            /* Return code */
Line 59: Line 58:
printf("DosOpenL error  return code = %u\n", rc);
printf("DosOpenL error  return code = %u\n", rc);
return 1;
return 1;


rc = DosWrite (hfFileHandle, (PVOID) uchFileData,
rc = DosWrite (hfFileHandle, (PVOID) uchFileData,
Line 66: Line 64:
printf("DosWrite error  return code = %u\n", rc);
printf("DosWrite error  return code = %u\n", rc);
return 1;
return 1;


rc = DosResetBuffer (hfFileHandle);
rc = DosResetBuffer (hfFileHandle);
Line 78: Line 75:
printf("DosSetFileSizeL error  return code = %u\n", rc);
printf("DosSetFileSizeL 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|DosProtectOpenL]]
*[[DosProtectOpenL]]
* [[OS2 API:CPI:DosProtectQueryFileInfo|DosProtectQueryFileInfo]]
*[[DosProtectQueryFileInfo]]
* [[OS2 API:CPI:DosQueryPathInfo|DosQueryPathInfo]]
*[[DosQueryPathInfo]]
 


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

Revision as of 16:10, 25 November 2016

Description

DosSetFileSizeL changes the size of a file.

Syntax

#define INCL DOSFILEMGR
#include  os2.h 

APIRET DosSetFileSizeL (HFILE hFile, LONGLONG cbSize)

Parameters

hFile HFILE) input
The handle of the file whose size to be changed.
cbSize LONGLONG) input
The new size, in bytes, of the file.

Return Code

ulrc APIRET) returns

DosSetFileSizeL returns one of the following values:

  • 0 NO_ERROR
  • ERROR_ACCESS_DENIED
  • ERROR_INVALID_HANDLE
  • 26 ERROR_NOT_DOS_DISK
  • 33 ERROR_LOCK_VIOLATION
  • 87 ERROR_INVALID_PARAMETER
  • 112 ERROR_DISK_FULL

Remarks

When DosSetFileSizeL is issued, the file must be open in a mode that allows write access.

The size of the open file can be truncated or extended. If the file size is being extended, the file system tries to allocate additional bytes in a contiguous (or nearly contiguous) space on the medium. The values of the new bytes are undefined.

Example Code

This example writes to a file named DOSMAN.DAT, resets the buffer, and changes the file size.

#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  ulWrote        = 0;      /* Number of bytes written by DosWrite */
UCHAR  uchFileName 20  = "dosman.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 = DosOpenL(uchFileName,  hfFileHandle,  ulAction, (LONGLONG)4,
FILE_ARCHIVED | FILE_NORMAL,
OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE  |
OPEN_ACCESS_READWRITE, 0L);
if (rc != NO_ERROR)  
printf("DosOpenL error  return code = %u\n", rc);
return 1;

rc = DosWrite (hfFileHandle, (PVOID) uchFileData,
sizeof (uchFileData),  ulWrote);
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 = DosSetFileSizeL (hfFileHandle, (LONGLONG)8);    /* Change file size */
if (rc != NO_ERROR)  
printf("DosSetFileSizeL error  return code = %u\n", rc);
return 1;

return NO_ERROR;

Related Functions