[comp.os.minix] mesg

cs00chs@unccvax.uncc.edu (charles spell) (09/12/90)

Not exaclty a power user's utility...but it is UNIX. man page included in
the source...
If there are any problems (hopefully minimal due to its simplicity) send
email to me. I'll send the fixed version to the beta dudes, who, in turn,
will release the OFFICIAL version.


Written: 09-09-90 (Netherlands date format)
---cut here------------------------------------------------------------------
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
/*****************************************************************************
* NAME 
*   mesg(1)
* SYNOPSIS
*   mesg [y|n]
* DESCRIPTION
*   'mesg n' will turn off group and world permissions of the user's terminal.
*   'mesg y' will enable group and world to write to the user's tty.
*    mesg with no parameters will put the writeable status onto stdout.
* DIAGNOSTICS
*   mesg returns 0 if tty is writeable by all (after executing mesg)
*                1 if tty is not writeable by all
*                2 on error
* FILES
*   /dev/tty*
* SEE ALSO
*   talk(1), write(1)
* AUTHOR
*   John J. Ribera, Jr. 09-09-90 (Netherlands format)
*/
main(argc, argv)
int  argc;
char **argv;
{
struct stat statb;
       char  *tty_name;
       char  *ttyname();

if ((tty_name = ttyname(0)) == -1) exit(2);
if (stat(tty_name, &statb) == -1) exit(2);
if (--argc) {
   if (*argv[1] == 'n') statb.st_mode &= 0755;
   else if (*argv[1] == 'y') statb.st_mode |= 022;
   else {
      fprintf(stderr, "mesg: usage: mesg [n|y]\n");
      exit(2);
   }
   if (chmod(tty_name, statb.st_mode) == -1) exit(2);
}
else
   printf((statb.st_mode & 002) ? "is y\n" : "is n\n");

if (statb.st_mode & 002) exit(0);
exit(1);
}

---cut here------------------------------------------------------------------
-- 
.--------------------------.  ...  |On the border of your mind lies a place
|uunet!mcnc!unccvax!cs00chs|  (")  |where dreams and reality are one...I will 
`--------------------------'-w-U-w-|take you there, for I am the subject...
\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\%\|the subject of your imagination. -Aldo Nova