home *** CD-ROM | disk | FTP | other *** search
- static char sccs_id[] = "@(#) unlink.c 1.2 " __DATE__ " HJR";
-
- /* unlink.c (c) Copyright 1990 H.Rogers */
- /* Complete re-write, 1994, Alun Jones. */
-
- /* Fixes default of forcible deletions! */
-
- #include <errno.h>
- #include "sys/unix.h"
- #include "sys/os.h"
-
- int
- unlink (char *file)
- {
- int r[10];
- os_error *e;
-
- file = __uname (file, 0);
- /* No filename given / no RISC OS equivalent
- */
- if (!*file)
- {
- errno = ENOENT;
- return (-1);
- }
-
- /* 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 (0x08, 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 (0x08, 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);
- }
-