summaryrefslogtreecommitdiff
path: root/release/src/router/busybox/init/mesg.c
diff options
context:
space:
mode:
Diffstat (limited to 'release/src/router/busybox/init/mesg.c')
-rw-r--r--release/src/router/busybox/init/mesg.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/release/src/router/busybox/init/mesg.c b/release/src/router/busybox/init/mesg.c
index 7b8acf65..ca230f36 100644
--- a/release/src/router/busybox/init/mesg.c
+++ b/release/src/router/busybox/init/mesg.c
@@ -1,25 +1,12 @@
+/* vi: set sw=4 ts=4: */
/*
- * mesg implementation for busybox
+ * mesg implementation for busybox
*
- * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
+ * Copyright (c) 2002 Manuel Novoa III <mjn3@codepoet.org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <unistd.h>
-#include <stdlib.h>
#include "libbb.h"
#ifdef USE_TTY_GROUP
@@ -28,31 +15,32 @@
#define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
#endif
-extern int mesg_main(int argc, char *argv[])
+int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int mesg_main(int argc, char **argv)
{
struct stat sb;
- char *tty;
- char c;
+ const char *tty;
+ char c = 0;
- if ((--argc == 0)
- || ((argc == 1) && (((c = **++argv) == 'y') || (c == 'n')))) {
- if ((tty = ttyname(STDERR_FILENO)) == NULL) {
+ if (--argc == 0
+ || (argc == 1 && ((c = **++argv) == 'y' || c == 'n'))
+ ) {
+ tty = xmalloc_ttyname(STDERR_FILENO);
+ if (tty == NULL) {
tty = "ttyname";
} else if (stat(tty, &sb) == 0) {
+ mode_t m;
if (argc == 0) {
- puts(((sb.st_mode & (S_IWGRP | S_IWOTH)) ==
- 0) ? "is n" : "is y");
+ puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
return EXIT_SUCCESS;
}
- if (chmod
- (tty,
- (c ==
- 'y') ? sb.st_mode | (S_IWGRP_OR_S_IWOTH) : sb.
- st_mode & ~(S_IWGRP | S_IWOTH)) == 0) {
+ m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
+ : sb.st_mode & ~(S_IWGRP|S_IWOTH);
+ if (chmod(tty, m) == 0) {
return EXIT_SUCCESS;
}
}
- bb_perror_msg_and_die("%s", tty);
+ bb_simple_perror_msg_and_die(tty);
}
bb_show_usage();
}