1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include "libbb.h"
- #if ENABLE_FEATURE_MESG_ENABLE_ONLY_GROUP
- #define S_IWGRP_OR_S_IWOTH S_IWGRP
- #else
- #define S_IWGRP_OR_S_IWOTH (S_IWGRP | S_IWOTH)
- #endif
- int mesg_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
- int mesg_main(int argc UNUSED_PARAM, char **argv)
- {
- struct stat sb;
- mode_t m;
- char c = 0;
- argv++;
- if (argv[0]
- && (argv[1] || ((c = argv[0][0]) != 'y' && c != 'n'))
- ) {
- bb_show_usage();
- }
-
- if (!isatty(STDIN_FILENO))
- bb_simple_error_msg_and_die("not a tty");
- xfstat(STDIN_FILENO, &sb, "stdin");
- if (c == 0) {
- puts((sb.st_mode & (S_IWGRP|S_IWOTH)) ? "is y" : "is n");
- return EXIT_SUCCESS;
- }
- m = (c == 'y') ? sb.st_mode | S_IWGRP_OR_S_IWOTH
- : sb.st_mode & ~(S_IWGRP|S_IWOTH);
- if (fchmod(STDIN_FILENO, m) != 0)
- bb_perror_nomsg_and_die();
- return EXIT_SUCCESS;
- }
|