unlink
raw OCR
Deletes a file.
Defined in header <io.h>
Syntax
#include <io.h>
int unlink(const char *filename);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
unlink deletes a file specified by filename. Any DOS drive, path, and file name can be used as a filename. Wildcards are not allowed.
Read-only files cannot be deleted by this call. To remove read-only files, first use chmod or _chmod to change the read-only attribute.
fe^
If your file is open, be sure to close it before unlinking it.
Return value
On successful completion, unlink returns 0. On error, it returns -1 and the global variable errno is set to one of the following values:
ENOENT Path or file name not found EACCES Permission denied
See also
Example
#include <stdio.h>
#include <io.h>
int main (void)
{
FILE *fp = fopenC junk, jnk", "w");
int status;
fprintf (fp,"junk");
status = access! "junk.jnk",0) ;
if (status == 0)
printfC'File exists\n");
else
printf("FiIe doesn't existXn");
fclose(fp) ;
unlink("junk. jnk");
status = access ("junk.jnk",0);
if (status == 0)
printfC'File exists\n"),
else
printfC'File doesn't exist\n");
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Stable link: /3.1/io.h/unlink/
· short form /3.1/unlink/