Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>chsize change size of file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
chsize                   Change Size of File

 #include <io.h>

 int        chsize(handle, size);
 int        handle;                      Handle referring to file
 long       size;                        New file size

    chsize() shortens or lengthens the file associated with 'handle' to
    the length specified in 'size'.  If the file is to be lengthened,
    null characters ('\0') are appended.  If it is to be shortened, the
    file is truncated and all data between the new end of file and old
    end of file is lost.

    Returns:    Zero if the file size is successfully changed, or -1 if
                an error occurred. On error, 'errno' is set to one of the
                following:

                    EACCES    the file is read only,
                    EBADF     file handle is invalid
                    ENOSPC    there is no space left on the disk.

  -------------------------------- Example ---------------------------------

    The following statements open a file for reading and writing. If the
    file length is greater than MAXSIZE when opened, the file length is
    reduced to maxsize.


          #include <io.h>
          #include <fcntl.h>
          #include <sys\types.h>
          #include <sys\stat.h>


          #define MAXSIZE  32768L
          int     fhndl, result;

          main()
          {
                fhndl = open("data", O_RDWR | O_CREAT, S_IREAD | I_WRITE);
                .
                .
                if (lseek(fhndl,0L,2) > MAXSIZE)
                   result = chsize(fhndl,MAXSIZE);
           }

See Also: close() creat() open()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson