home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume5 / smallc / part3 / vax / iovax.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.6 KB  |  125 lines

  1. /*    VAX fopen, fclose, fgetc, fputc, feof
  2.  * gawd is this gross - no buffering!
  3. */
  4. #include <stdio.h>
  5.  
  6. static    feofed[20];
  7. static    char    charbuf[1];
  8. static    retcode;
  9.  
  10. fopen(filnam, mod) char *filnam, *mod; {
  11.     if (*mod == 'w') {
  12.         filnam;
  13. #asm
  14.         pushl    r0
  15.         calls    $1,zunlink
  16. #endasm
  17.         filnam;
  18. #asm
  19.         pushl    $0644
  20.         pushl    r0
  21.         calls    $2,zcreat
  22.         movl    r0,_retcode
  23. #endasm
  24.         if (retcode < 0) {
  25.             return(NULL);
  26.         } else return(retcode);
  27.     }
  28.     filnam;
  29. #asm
  30.     pushl    $0    # read mode
  31.     pushl    r0
  32.     calls    $2,zopen
  33.     movl    r0,_retcode
  34. #endasm
  35.     feofed[retcode] = 0;
  36.     if (retcode < 0) return (NULL);
  37.     else return(retcode);
  38. }
  39.  
  40. fclose(unit) int unit; {
  41.     unit;
  42. #asm
  43.     pushl    r0
  44.     calls    $1,zclose
  45. #endasm
  46. }
  47.  
  48. fgetc(unit) int unit; {
  49.     unit;
  50. #asm
  51.     pushl    $1
  52.     pushl    $_charbuf
  53.     pushl    r0
  54.     calls    $3,zread
  55.     movl    r0,_retcode
  56. #endasm
  57.     if (retcode <= 0) {
  58.         feofed[unit] = 1;
  59.         return(EOF);
  60.     } else
  61.         return(charbuf[0]);
  62. }
  63.  
  64. fputc(c, unit) int c, unit; {
  65.     charbuf[0] = c;
  66.     unit;
  67. #asm
  68.     pushl    $1
  69.     pushl    $_charbuf
  70.     pushl    r0
  71.     calls    $3,zwrite
  72. #endasm
  73.     return(c);
  74. }
  75.  
  76. feof(unit) int unit; {
  77.     if (feofed[unit]) return(1);
  78.     else return(NULL);
  79. }
  80.  
  81. /*    Assembler assists    */
  82. #asm
  83.     .set    unlink,10
  84.     .set    creat,8
  85.     .set    open,5
  86.     .set    close,6
  87.     .set    read,3
  88.     .set    write,4
  89. zunlink:
  90.     .word    0x0000
  91.     chmk    $unlink
  92.     bcc    noerr
  93.     jmp    cerror
  94. zcreat:
  95.     .word    0x0000
  96.     chmk    $creat
  97.     bcc    noerr
  98.     jmp    cerror
  99. zopen:
  100.     .word    0x0000
  101.     chmk    $open
  102.     bcc    noerr
  103.     jmp    cerror
  104. zclose:
  105.     .word    0x0000
  106.     chmk    $close
  107.     bcc    noerr
  108.     jmp    cerror
  109. zread:
  110.     .word    0x0000
  111.     chmk    $read
  112.     bcc    noerr
  113.     jmp    cerror
  114. zwrite:
  115.     .word    0x0000
  116.     chmk    $write
  117.     bcc    noerr
  118.     jmp    cerror
  119.  
  120. cerror:
  121.     mnegl    $1,r0
  122.     ret
  123. noerr:    ret
  124. #endasm
  125.