home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / disk / archive / nspark_1 / nspark-1.7.5 / acorn.c next >
C/C++ Source or Header  |  1994-12-12  |  3KB  |  128 lines

  1. /*
  2.  * Operating System specific function (Acorn)
  3.  *
  4.  * $Header: acorn.c 1.1 93/03/05 $
  5.  * $Log:    acorn.c,v $
  6.  * Revision 1.1  93/03/05  14:34:04  arb
  7.  * Initial revision
  8.  * 
  9.  */
  10.  
  11. #include "spark.h"
  12. #include "date.h"
  13. #include "kernel.h"
  14. #include "swis.h"
  15.  
  16. #ifdef UNIX
  17. static char rcsid[] = "$Header: acorn.c 1.1 93/03/05 $";
  18. #endif
  19.  
  20. /*
  21.  * return the length of a file
  22.  */
  23. Word
  24. filesize(pathname)
  25.     char *pathname;
  26. {
  27.     int rc;
  28.     _kernel_osfile_block osblock;
  29.  
  30.     rc = _kernel_osfile(17, pathname, &osblock);
  31.     if (rc == _kernel_ERROR)
  32.     return(0);
  33.     /* Bit 1 is set if a file, bit 2 if a directory, both if image file */
  34.     if (rc & 1)
  35.     return ((Word)osblock.start);
  36.     else
  37.     return(0);
  38. }
  39.  
  40. /*
  41.  * test for the existance of a file or directory
  42.  */
  43. Ftype
  44. exist(pathname)
  45.     char *pathname;
  46. {
  47.     int rc;
  48.     _kernel_osfile_block osblock;
  49.  
  50.     rc = _kernel_osfile(17, pathname, &osblock);
  51.     if (rc == _kernel_ERROR)
  52.     return (NOEXIST);    /* assumes error was because file
  53.                        doesn't exist... could be wrong! */
  54.     if (rc & 1)
  55.     return (ISFILE);    /* might not be a regular file... (eg. image) */
  56.     if (rc & 2)
  57.     return (ISDIR);
  58.     else
  59.     return (NOEXIST);
  60. }
  61.     
  62. /*
  63.  * make a directory
  64.  */
  65. int
  66. makedir(pathname)
  67.     char *pathname;
  68. {
  69.     int rc;
  70.     _kernel_osfile_block osblock;
  71.  
  72.     osblock.start = 0;                /* Default number of entries */
  73.     rc = _kernel_osfile(8, pathname, &osblock);
  74.     if (rc == _kernel_ERROR)
  75.     return(-1);                   /* Should set errno */
  76.     else
  77.     return(0);
  78. }
  79.  
  80. /*
  81.  * stamp a file with date and time
  82.  */
  83. int
  84. filestamp(header, filename)
  85.     Header *header;
  86.     char *filename;
  87. {
  88.     int rc;
  89.     _kernel_osfile_block osblock;
  90.  
  91.     if ((header->load & (Word)0xfff00000) != (Word)0xfff00000)
  92.     return (0);    /* not a timestamp */
  93.  
  94.     osblock.load = header->load;
  95.     osblock.exec = header->exec;
  96.     osblock.end  = header->attr;
  97.     rc = _kernel_osfile(1, filename, &osblock);
  98.     if (rc == _kernel_ERROR)
  99.     return(-1);
  100.     else
  101.     return(0);
  102. }
  103.  
  104. /*
  105.  * read byte from stream (only one line from stdin supported)
  106.  */
  107. int
  108. read(fd, buffer, len)
  109.     int   fd;
  110.     void *buffer;
  111.     int   len;
  112. {
  113.     _kernel_swi_regs regs;
  114.     int carry;
  115.  
  116.     if (fd != 0)                   /* Only stdin, sorry! */
  117.     return(0);
  118.     regs.r[0] = (int)buffer;
  119.     regs.r[1] = len;
  120.     regs.r[2] = 1;                 /* Low/high values to store */
  121.     regs.r[3] = 255;
  122.     if (_kernel_swi_c(OS_ReadLine, ®s, ®s, &carry))
  123.     return(-1);                /* Error occurred */
  124.     if (carry)
  125.     return(-1);                /* Escape pressed */
  126.     return(regs.r[1]);             /* Return number of bytes read */    
  127. }
  128.