[Previous] [Contents] [Next]

remove()

Delete a file

Synopsis:

#include <stdio.h>

int remove( const char * filename );

Library:

libc

Description:

The remove() function deletes the file specified by filename.

Returns:

0
The operation was successful.
Nonzero
The operation failed (errno is set).

Errors:

EACCES
Search permission is denied for a component of path, or write permission is denied on the directory containing the link to be removed.
EBUSY
The directory named by path cannot be unlinked because it's being used by the system or another process, and the target filesystem or resource manager considers this to be an error.
ENAMETOOLONG
The path argument exceeds PATH_MAX in length, or a pathname component is longer than NAME_MAX.
ENOENT
The named file doesn't exist, or path is an empty string.
ENOSYS
The unlink() function isn't implemented for the filesystem specified by path.
ENOTDIR
A component of path isn't a directory.
EPERM
The file named by path is a directory, and either the calling process doesn't have the appropriate privileges, or the target filesystem or resource manager prohibits using unlink() on directories.
EROFS
The directory entry to be unlinked resides on a read-only filesystem.

Examples:

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
    if( remove( "vm.tmp" ) ) {
        puts( "Error removing vm.tmp!" );

        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

Classification:

ANSI

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

See also:

errno, unlink


[Previous] [Contents] [Next]