Borland C++ reference

chsize

raw OCR

Changes the file size.

Defined in header <io.h>

Syntax

#include <io.h>
int chsize(int handle, long size);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

chsize changes the size of the file associated with handle. It can truncate or extend the file, depending on the value of size compared to the file's original size.

The mode in which you open the file must allow writing.

If chsize extends the file, it will append null characters (\0). If it truncates the file, all data beyond the new end-of-file indicator is lost.

Return value

On success, chsize returns 0. On failure, it returns -1 and the global variable errno is set to one of the following:

EACCESS Permission denied

EBADFBad file number
ENOSPC UNIX—not DOS

See also

Example

#include <string.h>
#include <fcntl.h>
#include <io.h>

int main (void)
{
   int handle;
   char buf[ll] =  "0123456789";

   /* create a text file containing  10 bytes */
   handle = open ("DUMMY.FIL", 0_CREAT);
   write(handle, buf, strlen(buf ));
   /* truncate the file to  5 bytes in size */
   chsize (handle, 5);

   /* close the file */
   close(handle);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.