home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZIP19P1.ZIP / atari / atari.c next >
C/C++ Source or Header  |  1993-01-23  |  2KB  |  126 lines

  1. /*
  2.  * ATARI.C
  3.  *
  4.  * Necessary interface functions, mostly for conversion
  5.  * of path names.
  6.  */
  7. #ifdef ATARI_ST
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <tos.h>
  12. #include <ext.h>
  13.  
  14. #define FNMAX 256
  15. #define OF(sig) sig
  16.  
  17. char *st_fn OF((char *));
  18.  
  19. char *st_fn(s)
  20. char *s;
  21. {
  22. static char tosname [ FNMAX ];
  23. char *t = tosname;
  24.  
  25.   while ( *t=*s++ ) {
  26.     if ( *t == '/' )
  27.       *t = '\\';
  28.     t++;
  29.   }
  30.   
  31.   return(tosname);
  32. }
  33.  
  34. int st_unlink(f)
  35. char *f;
  36. {
  37.   return(unlink(st_fn(f)));
  38. }
  39.  
  40. /* Fake chmod with minimalistic functionality.
  41.  * [ anyway people will be in trouble with the readonly files
  42.  *   produces by this, since 'normal' users don't own the
  43.  *   'tools' to manipulate these. ]
  44.  */
  45. int st_chmod(f, a)
  46. char *f;                /* file path */
  47. int a;                  /* attributes returned by getfileattr() */
  48. /* Give the file f the attributes a, return non-zero on failure */
  49. {
  50.   if ( ! ( a & S_IWRITE ) )
  51.     if (Fattrib(st_fn(f), 1, FA_READONLY) < 0 )
  52.       return(-1);
  53.   return 0;
  54. }
  55.  
  56. /*
  57.  * mktemp is not part of the Turbo C library.
  58.  */ 
  59. char *st_mktemp(s)
  60. char *s;
  61. {
  62. char *t;
  63. long i;
  64.   for(t=s; *t; t++)
  65.     if ( *t == '/' )
  66.       *t = '\\';
  67.   t -= 6;
  68.   i = (unsigned long)s % 1000000L;
  69.   do {
  70.     sprintf(t, "%06ld", i++);
  71.   } while ( Fsfirst(s, 0x21) == 0 );
  72.   return(s);
  73. }
  74.  
  75. FILE *st_fopen(f,m)
  76. char *f;
  77. char *m;
  78. {
  79.   return(fopen(st_fn(f),m));
  80. }
  81.  
  82. int st_open(f,m)
  83. char *f;
  84. int m;
  85. {
  86.   return(open(st_fn(f),m));
  87. }
  88.  
  89. int st_stat(f, b)
  90. char *f;
  91. struct stat *b;
  92. {
  93.   return(stat(st_fn(f),b));
  94. }
  95.  
  96. int st_findfirst(n,d,a)
  97. char *n;
  98. struct ffblk *d;
  99. int a;
  100. {
  101.   return(findfirst( st_fn(n),(struct ffblk *)d,a));
  102. }
  103.  
  104.  
  105. int st_rename(s, d)
  106. char *s, *d;
  107. {
  108. char tosname [ FNMAX ];
  109. char *t = tosname;
  110.  
  111.   while ( *t=*s++ ) {
  112.     if ( *t == '/' )
  113.       *t = '\\';
  114.     t++;
  115.   }
  116.   return(rename(tosname, st_fn(d)));
  117. }  
  118.  
  119. int st_rmdir(d)
  120. char *d;
  121. {
  122.   return(Ddelete(st_fn(d)));
  123. }
  124.  
  125. #endif /* ?ATARI_ST */
  126.