Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/chsize.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/chsize.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/chsize.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/chsize.html on line 8

chsize()

Change the size of a file

Synopsis:

#include <unistd.h>

int chsize( int filedes, 
            long size );

Arguments:

filedes
A file descriptor for the file whose size you want to change.
size
The new size of the file, in bytes.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The chsize() function extends or truncates the file specified by filedes to size bytes The file is padded with NUL ('\0') characters if it needs to be extended.


Note: The chsize() function ignores advisory locks that may have been set with the fcntl() function.

Returns:

0
Success.
-1
An error occurred.

Errors:

EBADF
The filedes argument isn't a valid file descriptor, or the file isn't opened for writing.
ENOSPC
There isn't enough space left on the device to extend the file.
ENOSYS
The chsize() function isn't implemented for the filesystem specified by filedes.

Examples:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>

int main( void )
{
    int  filedes;

    filedes= open( "file", O_RDWR | O_CREAT,
        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
    if( filedes!= -1 ) {
        if( chsize( filedes, 32 * 1024L ) != 0 ) {
            printf( "Error extending file\n" );
        }
        close( filedes);
        
        return EXIT_SUCCESS;
    }
    
    return EXIT_FAILURE;
}

Classification:

QNX 4

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

close(), creat(), errno, ftruncate(), open()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/c/chsize.html on line 190

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/c/chsize.html on line 190