home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/src/unix/c/RCS/unlink,v $
- * $Date: 1996/10/30 22:04:51 $
- * $Revision: 1.3 $
- * $State: Rel $
- * $Author: unixlib $
- *
- * $Log: unlink,v $
- * Revision 1.3 1996/10/30 22:04:51 unixlib
- * Massive changes made by Nick Burret and Peter Burwood.
- *
- * Revision 1.2 1996/05/06 09:01:35 unixlib
- * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
- * Saved for 3.7a release.
- *
- * Revision 1.1 1996/04/19 21:35:27 simon
- * Initial revision
- *
- * Complete re-write, 1994, Alun Jones.
- ***************************************************************************/
-
- static const char rcs_id[] = "$Id: unlink,v 1.3 1996/10/30 22:04:51 unixlib Rel $";
-
- /* Fixes default of forcible deletions! */
-
- #include <errno.h>
- #include <unistd.h>
- #include <sys/os.h>
- #include <sys/swis.h>
-
- int
- unlink (char *file)
- {
- int r[10];
- _kernel_oserror *e;
-
- /* No filename given / no RISC OS equivalent
- */
- if (!*file)
- {
- errno = ENOENT;
- return (-1);
- }
-
- file = __uname (file, 0);
-
- /* Get file's catalogue entry (unfortunately
- * uses wildcards. Still, shouldn't be a major problem)
- */
- r[0] = 17;
- r[1] = (int) file;
- if (e = os_swi (OS_File, r))
- {
- __seterr (e);
- return (-1);
- }
-
- /* What was the file's type ?
- */
- switch (r[0])
- {
- case 0: /* Non-existent */
- errno = ENOENT;
- return (-1);
- case 2: /* Directory */
- case 3: /* Image FS */
- errno = EISDIR;
- return (-1);
- default: /* File */
- break;
- }
-
- /* Try to zap the file
- */
- r[0] = 6;
- r[1] = (int) file;
- if (e = os_swi (OS_File, r))
- {
- /* Should really check for EACCES and EROFS,
- * but these errno's seem to float around for
- * different FS's!
- */
- __seterr (e);
- return (-1);
- }
-
- return (0);
- }
-