home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / s2 / mesg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1975-05-13  |  662 b   |  50 lines

  1. /*
  2.  * mesg -- set current tty to accept or
  3.  *    forbid write permission.
  4.  *
  5.  *    mesg [y] [n]
  6.  *        y allow messages
  7.  *        n forbid messages
  8.  */
  9.  
  10. int    sbuf[40];
  11.  
  12. main(argc, argv)
  13. char *argv[];
  14. {
  15.     register char *tty;
  16.  
  17.     tty = "/dev/ttyx";
  18.     tty[8] = ttyn(1);
  19.     if(stat(tty, sbuf) < 0) {
  20.         write(2, "cannot stat\n", 12);
  21.         exit(1);
  22.     }
  23.     if(argc < 2) {
  24.         if(sbuf[2] & 02)
  25.             goto no;
  26.         goto yes;
  27.     }
  28.     if(*argv[1] == 'y')
  29.         goto yes;
  30.  
  31. no:
  32.     if(chmod(tty, 0600) < 0)
  33.         goto bad;
  34.     goto was;
  35.  
  36. yes:
  37.     if(chmod(tty, 0622) < 0)
  38.         goto bad;
  39.  
  40. was:
  41.     if(sbuf[2] & 02)
  42.         write(2, "was y\n", 6); else
  43.         write(2, "was n\n", 6);
  44.     exit(0);
  45.  
  46. bad:
  47.     write(2, "cannot change mode\n", 19);
  48.     exit(1);
  49. }
  50.