Chapter Contents

Previous

Next
unlink

unlink



Delete a File

Portability: POSIX.1 conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
IMPLEMENTATION
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <fcntl.h>

int unlink(const char *name);

The synopsis for the POSIX implementation is

#include <sys/types.h>
#include <unistd.h>

int unlink(const char *name)

You may use either set of header files in your program.


DESCRIPTION

Under OS/390, the unlink function deletes the OS/390 disk file, PDS member, or HFS file specified by the string that is pointed to by name .

Under CMS, unlink deletes the disk file specified by the CMS string that is pointed to by name .


RETURN VALUE

The unlink function returns 0 if the file is deleted. If the file cannot be deleted or name is invalid, -1 is returned.


CAUTION

OS/390

For ddn style filenames that do not refer to a PDS member, unlink means "to make empty." Other style filenames are deleted and uncataloged.

CMS

If the fileid has a blank filemode, it defaults to A1 . The name function should not contain wild-card values such as * or = .

POSIX

For an USS HFS file, the directory entry is deleted. However, the file itself is deleted only when there are no links that refer to it.


IMPLEMENTATION

unlink is an alternate name for remove . See the implementation details for remove.


EXAMPLE

#include <fcntl.h>
#include <stdio.h>

main()
{
   int rc;

   rc = unlink("cms:testfile text a1");

   if (rc == 0)
      puts("The file has been unlinked/deleted.");
   else
      puts("The file could not be deleted.");
}


RELATED FUNCTIONS

link


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.