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 6.0 - <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 lengthened, null
    characters ('\0') are appended.  If it is shortened, the file is
    truncated and all data from that point to the old end of file is
    lost.

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

                    EBADF     file handle is invalid
                    ENOSPC    there is no space left on the disk
                    EACCES    files is locked against accss (MS-DOS 3.0 and
                    higher), or the file is read only

 Portability:   Not supported by ANSI standard.

   -------------------------------- 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);
                 .
                 .
               (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