home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib32.zoo / pgrp.c < prev    next >
C/C++ Source or Header  |  1993-06-17  |  2KB  |  111 lines

  1. #ifdef __TURBOC__
  2. #include <sys\types.h>
  3. #else
  4. #include <sys/types.h>
  5. #endif
  6. #include <unistd.h>
  7. #include <osbind.h>
  8. #include <mintbind.h>
  9. #include <errno.h>
  10. #include <ioctl.h>
  11. #include <fcntl.h>
  12. #include "lib.h"
  13.  
  14. extern int __mint;
  15.  
  16. pid_t
  17. getpgrp()
  18. {
  19.   return __mint ? Pgetpgrp() : 0;
  20. }
  21.  
  22. int
  23. _bsd_setpgrp(pid, grp)
  24.   int pid, grp;
  25. {
  26.   int r = 0;
  27.  
  28.   if (__mint) {
  29.     r = Psetpgrp(pid, grp);
  30.     if (r < 0) {
  31.       errno = -r;
  32.       r = -1;
  33.     }
  34.   }
  35.   return r;
  36. }
  37.  
  38. int
  39. setpgrp()
  40. {
  41.   return __mint ? Psetpgrp(0, 0) : 0;
  42. }
  43.  
  44. int
  45. _bsd_getpgrp(pid)
  46.   int pid;
  47. {
  48.   if (__mint >= 103) return _bsd_setpgrp(pid, -1);
  49.   return 0;
  50. }
  51.  
  52. int
  53. setpgid(pid, pgid)
  54.   pid_t pid, pgid;
  55. {
  56.   int r = 0;
  57.  
  58.   if (__mint) {
  59.     r = Psetpgrp((int) pid, (int) pgid);
  60.     if (r < 0) {
  61.       errno = -r;
  62.       r = -1;
  63.     }
  64.   }
  65.   return r;
  66. }
  67.  
  68. pid_t
  69. setsid()
  70. {
  71.   long tty_pgrp;
  72.   long prc_pgrp;
  73.   int tty_fd;
  74.   int rc;
  75.  
  76.   if (!__mint) {
  77.     errno = EINVAL;
  78.     return (pid_t) -1;
  79.   }
  80.   prc_pgrp = Pgetpgrp();
  81.   if (prc_pgrp != Pgetpid()) {
  82.     if (isatty(-1)) {
  83.       tty_fd = open("/dev/tty", O_RDWR | O_NOCTTY);
  84.       if (tty_fd < __SMALLEST_VALID_HANDLE) {
  85.         return (pid_t) -1;
  86.       }
  87.       rc = (int) Fcntl(-1, &tty_pgrp, TIOCGPGRP);
  88.       if (rc < 0) {
  89.         errno = -rc;
  90.         return (pid_t) -1;
  91.       }
  92.       if (tty_pgrp == prc_pgrp) {
  93.         tty_pgrp = 0;
  94.         rc = (int) Fcntl(-1, &tty_pgrp, TIOCSPGRP);
  95.         if (rc < 0) {
  96.           errno = -rc;
  97.           return (pid_t) -1;
  98.         }
  99.       }
  100.       if (ioctl(tty_fd, TIOCNOTTY, 0) < 0) return -1;
  101.       (void) close(tty_fd);
  102.     }
  103.   }
  104.   rc = (int) Psetpgrp(0, 0);
  105.   if (rc < 0) {
  106.     errno = -rc;
  107.     rc = -1;
  108.   }
  109.   return (pid_t) rc;
  110. }
  111.