/RISCOS/unixstuff.c

http://unladen-swallow.googlecode.com/ · C · 74 lines · 58 code · 13 blank · 3 comment · 8 complexity · 8fda7123b13ca2b94bc81512db24704e MD5 · raw file

  1. /* Fudge unix isatty and fileno for RISCOS */
  2. #include "unixstuff.h"
  3. #include <math.h>
  4. #include <time.h>
  5. #include "oslib/osfile.h"
  6. int fileno(FILE *f)
  7. { return (int)f;
  8. }
  9. int isatty(int fn)
  10. { return (fn==fileno(stdin));
  11. }
  12. bits unixtime(bits ld,bits ex)
  13. { ld&=0xFF;
  14. ld-=51;
  15. if(ex<1855547904U) ld--;
  16. ex-=1855548004U;
  17. return ex/100+42949673U*ld-ld/25;
  18. }
  19. /* from RISC OS infozip, preserves filetype in ld */
  20. int acorntime(bits *ex, bits *ld, time_t utime)
  21. {
  22. unsigned timlo; /* 3 lower bytes of acorn file-time plus carry byte */
  23. unsigned timhi; /* 2 high bytes of acorn file-time */
  24. timlo = ((unsigned)utime & 0x00ffffffU) * 100 + 0x00996a00U;
  25. timhi = ((unsigned)utime >> 24);
  26. timhi = timhi * 100 + 0x0000336eU + (timlo >> 24);
  27. if (timhi & 0xffff0000U)
  28. return 1; /* calculation overflow, do not change time */
  29. /* insert the five time bytes into loadaddr and execaddr variables */
  30. *ex = (timlo & 0x00ffffffU) | ((timhi & 0x000000ffU) << 24);
  31. *ld = (*ld & 0xffffff00U) | ((timhi >> 8) & 0x000000ffU);
  32. return 0; /* subject to future extension to signal overflow */
  33. }
  34. int isdir(char *fn)
  35. { int ob;
  36. if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
  37. switch (ob)
  38. { case osfile_IS_DIR:return 1;
  39. case osfile_IS_IMAGE:return 1;
  40. }
  41. return 0;
  42. }
  43. int isfile(char *fn)
  44. { int ob;
  45. if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
  46. switch (ob)
  47. { case osfile_IS_FILE:return 1;
  48. case osfile_IS_IMAGE:return 1;
  49. }
  50. return 0;
  51. }
  52. int object_exists(char *fn)
  53. { int ob;
  54. if(xosfile_read_stamped_no_path(fn,&ob,0,0,0,0,0)) return 0;
  55. switch (ob)
  56. { case osfile_IS_FILE:return 1;
  57. case osfile_IS_DIR:return 1;
  58. case osfile_IS_IMAGE:return 1;
  59. }
  60. return 0;
  61. }