#include <sys/stat.h>
#include <time.h>
#include <unistd.h>
-#include <utmp.h>
+#include <utmpx.h>
#include "c.h"
#include "carefulputc.h"
const char *dst_tty_name;
};
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
{
+ FILE *out = stdout;
fputs(USAGE_HEADER, out);
fprintf(out,
_(" %s [options] <user> [<ttyname>]\n"),
fputs(_("Send a message to another user.\n"), out);
fputs(USAGE_OPTIONS, out);
- fputs(USAGE_HELP, out);
- fputs(USAGE_VERSION, out);
-
- fprintf(out, USAGE_MAN_TAIL("write(1)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+ printf(USAGE_HELP_OPTIONS(16));
+ printf(USAGE_MAN_TAIL("write(1)"));
+ exit(EXIT_SUCCESS);
}
/*
*/
static int check_utmp(const struct write_control *ctl)
{
- struct utmp *u;
+ struct utmpx *u;
int res = 1;
- utmpname(_PATH_UTMP);
- setutent();
+ utmpxname(_PATH_UTMP);
+ setutxent();
- while ((u = getutent())) {
+ while ((u = getutxent())) {
if (strncmp(ctl->dst_login, u->ut_user, sizeof(u->ut_user)) == 0 &&
strncmp(ctl->dst_tty_name, u->ut_line, sizeof(u->ut_line)) == 0) {
res = 0;
}
}
- endutent();
+ endutxent();
return res;
}
*/
static void search_utmp(struct write_control *ctl)
{
- struct utmp *u;
+ struct utmpx *u;
time_t best_atime = 0, tty_atime;
int num_ttys = 0, valid_ttys = 0, tty_writeable = 0, user_is_me = 0;
char path[sizeof(u->ut_line) + 6];
- utmpname(_PATH_UTMP);
- setutent();
+ utmpxname(_PATH_UTMP);
+ setutxent();
- while ((u = getutent())) {
+ while ((u = getutxent())) {
if (strncmp(ctl->dst_login, u->ut_user, sizeof(u->ut_user)) != 0)
continue;
num_ttys++;
}
}
- endutent();
+ endutxent();
if (num_ttys == 0)
errx(EXIT_FAILURE, _("%s is not logged in"), ctl->dst_login);
if (valid_ttys == 0) {
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case 'h':
- usage(stdout);
+ usage();
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
if (get_terminal_name(&ctl.src_tty_path, &ctl.src_tty_name, NULL) == 0) {
do_write(&ctl);
break;
default:
- usage(stderr);
+ errtryhelp(EXIT_FAILURE);
}
free(ctl.dst_tty_path);
return EXIT_SUCCESS;