1: static char *sccsid = "@(#)mesg.c	4.3 (Berkeley) 3/13/86";
   2: /*
   3:  * mesg -- set current tty to accept or
   4:  *	forbid write permission.
   5:  *
   6:  *	mesg [y] [n]
   7:  *		y allow messages
   8:  *		n forbid messages
   9:  */
  10: 
  11: #include <stdio.h>
  12: #include <sys/types.h>
  13: #include <sys/stat.h>
  14: 
  15: struct stat sbuf;
  16: 
  17: char *tty;
  18: char *ttyname();
  19: 
  20: main(argc, argv)
  21: char *argv[];
  22: {
  23:     int r=0;
  24:     tty = ttyname(2);
  25:     if (tty == 0)
  26:         exit(13);
  27:     if(stat(tty, &sbuf) < 0) error("cannot stat");
  28:     if(argc < 2) {
  29:         if(sbuf.st_mode & 020)
  30:             fprintf(stderr,"is y\n");
  31:         else {  r=1;
  32:             fprintf(stderr,"is n\n");
  33:         }
  34:     } else  switch(*argv[1]) {
  35:         case 'y':
  36:             newmode(sbuf.st_mode|020); break;
  37: 
  38:         case 'n':
  39:             newmode(sbuf.st_mode&~020); r=1; break;
  40: 
  41:         default:
  42:             error("usage: mesg [y] [n]");
  43:         }
  44:     exit(r);
  45: }
  46: 
  47: error(s)
  48: char *s;
  49: {
  50:     fprintf(stderr,"mesg: %s\n",s);
  51:     exit(-1);
  52: }
  53: 
  54: newmode(m)
  55: {
  56:     if(chmod(tty,m)<0)
  57:         error("cannot change mode");
  58: }

Defined functions

error defined in line 47; used 3 times
main defined in line 20; never used
newmode defined in line 54; used 2 times

Defined variables

sbuf defined in line 15; used 4 times
sccsid defined in line 1; never used
tty defined in line 17; used 4 times
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1089
Valid CSS Valid XHTML 1.0 Strict