home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / ioctl.c < prev    next >
C/C++ Source or Header  |  1992-09-05  |  2KB  |  111 lines

  1. /*
  2.  * ioctl() emulation for MiNT; written by Eric R. Smith and placed
  3.  * in the public domain
  4.  */
  5.  
  6. #include <errno.h>
  7. #include <mintbind.h>
  8. #include <ioctl.h>
  9. #include <fcntl.h>    /* for __open_stat */
  10. #include <unistd.h>
  11. #include <linea.h>    /* for TIOCGWINSZ under TOS */
  12.  
  13. extern int __mint;    /* MiNT version */
  14. int _ttydisc = NTTYDISC;
  15. int _ldisc = LLITOUT;
  16.  
  17. /* in read.c */
  18. extern struct tchars __tchars;
  19. extern struct ltchars __ltchars;
  20.  
  21. int ioctl(fd, cmd, arg)
  22.     int fd, cmd;
  23.     void *arg;
  24. {
  25.     long r;
  26.     int istty = isatty(fd);
  27.     struct sgttyb *sg = (struct sgttyb *) arg;
  28.  
  29.     if (istty) {
  30.         if (cmd == TIOCGETD) {
  31.             *((int *)arg) = _ttydisc;
  32.             return 0;
  33.         } else if (cmd == TIOCSETD) {
  34.             _ttydisc = *((int *)arg);
  35.             return 0;
  36.         } else if (cmd == TIOCLGET) {
  37.             *((int *)arg) = _ldisc;
  38.             return 0;
  39.         } else if (cmd == TIOCLSET) {
  40.             _ldisc = *((int *)arg);
  41.             return 0;
  42.         } else if (cmd == TIOCSWINSZ && __mint < 9) {
  43.             return 0;
  44.         } else if (cmd == TIOCGWINSZ && __mint < 9) {
  45.             struct winsize *win = (struct winsize *)arg;
  46.  
  47. #ifndef __SOZOBON__
  48.             (void)linea0();
  49. #else /* __SOZOBON__ */
  50.             linea0();
  51. #endif /* __SOZOBON__ */
  52.             win->ws_row = V_CEL_MY + 1;
  53.             win->ws_col = V_CEL_MX + 1;
  54.             win->ws_xpixel = V_X_MAX;
  55.             win->ws_ypixel = V_Y_MAX;
  56.             return 0;
  57.         }
  58.     }
  59.  
  60.     if (__mint) {
  61.         r = Fcntl(fd, arg, cmd);
  62.     }
  63.     else if (istty) {
  64.         r = 0;
  65.         switch(cmd) {
  66.         case TIOCSETP:
  67.             fd = __OPEN_INDEX(fd);
  68.             if (fd < 0 || fd >= __NHANDLES)
  69.                 fd = __NHANDLES - 1;
  70.             __open_stat[fd].flags = sg->sg_flags;
  71.             break;
  72.         case TIOCGETP:
  73.             fd = __OPEN_INDEX(fd);
  74.             if (fd < 0 || fd >= __NHANDLES)
  75.                 fd = __NHANDLES - 1;
  76.             sg->sg_flags = __open_stat[fd].flags;
  77.             sg->sg_ispeed = sg->sg_ospeed = 0;
  78.             sg->sg_erase = 'H' & 0x1f;
  79.             sg->sg_kill = 'U' & 0x1f;
  80.             break;
  81.         case TIOCGETC:
  82.             *((struct tchars *)arg) = __tchars;
  83.             break;
  84.         case TIOCSETC:
  85.             __tchars = *((struct tchars *)arg);
  86.             break;
  87.         case TIOCGLTC:
  88.             *((struct ltchars *)arg) = __ltchars;
  89.             break;
  90.         case TIOCSLTC:
  91.             __ltchars = *((struct ltchars *)arg);
  92.             break;
  93.         case TIOCGPGRP:
  94.             *((long *)arg) = 0;
  95.             break;
  96.         case TIOCSPGRP:
  97.             break;
  98.         default:
  99.             r = -EINVAL;
  100.         }
  101.     }
  102.     else
  103.         r = -EINVAL;
  104.  
  105.     if (r < 0) {
  106.         errno = (int) -r;
  107.         return -1;
  108.     }
  109.     return (int) r;
  110. }
  111.