[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


unlink

Delete (unlink) a file.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <unistd.h>
int unlink(const char *path);
Parameters:

Parameters for this facility are:

path  
const char *  
A pathname of the file to remove  

Remarks:

The function unlink() removes the specified file from the directory. Example of usage is given in "Example of unlink() usage."

Return:

If successful, unlink() returns zero. If unsuccessful, it returns a negative one.

See Also:

"rmdir"

"mkdir"

Example of unlink() usage.:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h> 

#define SIZE FILENAME_MAX

int main(void)
{
	FILE *fp;
	char fname[SIZE] = "Test.txt";
	
	/* create a file */
	if( (fp =fopen( fname,"w") ) == NULL )
	{
		printf("Can not open %s for writing", fname);
		exit( EXIT_FAILURE);
	}
	else printf("%s was opened for writing\n",fname);

	/* display it is available */
	if( !fclose(fp) ) printf("%s was closed\n",fname);

	/* delete file */
	if( unlink(fname) )
	{
		printf("%s was not deleted",fname);
		exit( EXIT_FAILURE );
	}

	/* show it can't be re-opened */
	if( (fp =fopen( fname,"r") ) == NULL )
	{
		printf("Can not open %s for reading it was deleted",
				 fname);
		exit( EXIT_FAILURE);
	}
	else printf("%s was opened for reading\n",fname);

	return 0;
}

Result
Test.txt was opened for writing
Test.txt was closed
Can not open Test.txt for reading it was deleted


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000