This function is compatible with the following targets:
|
EMB/RTOS
|
|
#include <unistd.h>
int unlink(const char *path);Parameters:
Parameters for this facility are:
The function unlink() removes the specified file from the directory. Example of usage is given in "Example of unlink() usage."
If successful, unlink() returns zero. If unsuccessful, it returns a negative one.
#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