home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / src / unix / c / unlink < prev    next >
Encoding:
Text File  |  1994-09-30  |  1.3 KB  |  69 lines

  1. static char sccs_id[] = "@(#) unlink.c 1.2 " __DATE__ " HJR";
  2.  
  3. /* unlink.c (c) Copyright 1990 H.Rogers */
  4. /* Complete re-write, 1994, Alun Jones. */
  5.  
  6. /* Fixes default of forcible deletions! */
  7.  
  8. #include <errno.h>
  9. #include "sys/unix.h"
  10. #include "sys/os.h"
  11.  
  12. int
  13. unlink (char *file)
  14. {
  15.   int r[10];
  16.   os_error *e;
  17.  
  18.   file = __uname (file, 0);
  19.   /* No filename given / no RISC OS equivalent
  20.    */
  21.   if (!*file)
  22.     {
  23.       errno = ENOENT;
  24.       return (-1);
  25.     }
  26.  
  27.   /* Get file's catalogue entry (unfortunately
  28.    * uses wildcards. Still, shouldn't be a major problem)
  29.    */
  30.   r[0] = 17;
  31.   r[1] = (int) file;
  32.   if (e = os_swi (0x08, r))
  33.     {
  34.       __seterr (e);
  35.       return (-1);
  36.     }
  37.  
  38.   /* What was the file's type ?
  39.    */
  40.   switch (r[0])
  41.     {
  42.     case 0:            /* Non-existent */
  43.       errno = ENOENT;
  44.       return (-1);
  45.     case 2:            /* Directory    */
  46.     case 3:            /* Image FS             */
  47.       errno = EISDIR;
  48.       return (-1);
  49.     default:            /* File                 */
  50.       break;
  51.     }
  52.  
  53.   /* Try to zap the file
  54.    */
  55.   r[0] = 6;
  56.   r[1] = (int) file;
  57.   if (e = os_swi (0x08, r))
  58.     {
  59.       /* Should really check for EACCES and EROFS,
  60.        * but these errno's seem to float around for
  61.        * different FS's!
  62.        */
  63.       __seterr (e);
  64.       return (-1);
  65.     }
  66.  
  67.   return (0);
  68. }
  69.