[hackers] [ubase] Add mesg(1) || sin

From: <git_AT_suckless.org>
Date: Sat, 26 Jul 2014 16:33:18 +0200

commit 47092bd9b600d71a30af1f074742c9fe240c9176
Author: sin <sin_AT_2f30.org>
Date: Sat Jul 26 15:31:44 2014 +0100

    Add mesg(1)
    
    No manpage yet.

diff --git a/Makefile b/Makefile
index 37d4ec3..992c570 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -53,6 +53,7 @@ SRC = \
         login.c \
         lsmod.c \
         lsusb.c \
+ mesg.c \
         mknod.c \
         mkswap.c \
         mount.c \
diff --git a/mesg.c b/mesg.c
new file mode 100644
index 0000000..a44a098
--- /dev/null
+++ b/mesg.c
_AT_@ -0,0 +1,53 @@
+/* See LICENSE file for copyright and license details. */
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "util.h"
+
+static void
+usage(void)
+{
+ eprintf("usage: %s [n|y]
", argv0);
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct stat sb;
+ mode_t mode;
+
+ ARGBEGIN {
+ default:
+ usage();
+ } ARGEND;
+
+ if (argc > 1)
+ usage();
+
+ if (isatty(STDIN_FILENO) == 0)
+ eprintf("stdin: not a tty
");
+
+ if (fstat(STDIN_FILENO, &sb) < 0)
+ eprintf("fstat stdin:");
+
+ if (argc == 0) {
+ puts(sb.st_mode & (S_IWGRP | S_IWOTH) ? "is y" : "is n");
+ return EXIT_SUCCESS;
+ }
+
+ if (argv[0][0] == 'y')
+ mode = sb.st_mode | S_IWGRP | S_IWOTH;
+ else if (argv[0][0] == 'n')
+ mode = sb.st_mode & ~(S_IWGRP | S_IWOTH);
+ else
+ usage();
+
+ if (fchmod(STDIN_FILENO, mode) < 0)
+ eprintf("fchmod stdin:");
+
+ return EXIT_SUCCESS;
+}
Received on Sat Jul 26 2014 - 16:33:18 CEST

This archive was generated by hypermail 2.3.0 : Sat Jul 26 2014 - 16:36:08 CEST