dos12.hlp (Table of Contents; Topic list)
DosNewSize (1.2)
Function Group  Overview                          Up Next Previous
────────────────────────────────────────────────────────────────────────────
 
#define INCL_DOSFILEMGR
 
USHORT DosNewSize(hf, ulNewSize)
HFILE hf;           /* file handle      */
ULONG ulNewSize;    /* new size of file */
 
The DosNewSize function changes the size of the specified file. The function
can be used to truncate or extend a file. If a file is extended, the value
of the new bytes is undefined.
 
The DosNewSize function is a family API function.
 
Parameter  Description
────────────────────────────────────────────────────────────────────────────
 
hf         Identifies the file to be changed. This handle must have been
           created previously by using the DosOpen function.
 
ulNewSize  Specifies the file's new size (in bytes).
 
Return Value
 
The return value is zero if the function is successful. Otherwise, it is an
error value, which may be one of the following:
 
     ERROR_ACCESS_DENIED
     ERROR_DISK_FULL
     ERROR_INVALID_HANDLE
     ERROR_INVALID_PARAMETER
     ERROR_LOCK_VIOLATION
     ERROR_NOT_DOS_DISK
 
Comments
 
The DosNewSize function applies only to files that have been opened for
writing. To change the size of a read-only file, first change the file's
attributes by using the DosSetFileMode function, then open the file for
writing.
 
If the function extends a file, the system will attempt to allocate sectors
that are contiguous with the existing file sectors.
 
Example
 
This example opens the file abc and calls the DosNewSize function to set the
file's size to 100 bytes. If the file already exists and is larger than 100
bytes, it is truncated to 100 bytes. If the file is smaller than 100 bytes,
or if it was created by using the DosOpen function, it is expanded to 100
bytes.
 
HFILE hf;
USHORT usAction;
DosOpen("abc", &hf, &usAction, 0L, FILE_NORMAL,
    FILE_OPEN | FILE_CREATE,
    OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYREADWRITE, 0L);
DosNewSize(hf, 100L);
 
See Also
 
DosOpen, DosQFileInfo, DosSetFileMode
 
                                      ♦