On Wed, Jul 27, 2011 at 1:53 PM, Ralf Friedl <[email protected]> wrote: > [email protected] wrote: >> >> On Wed, Jul 27, 2011 at 11:29 AM, Matthias Andree <[email protected]> >> wrote: >> >>> >>> Re printf, adding a format string ("%s") is absolutely necessary. >>> Else use fputs(ut->ut_user, stdout) >> >> It was about saving bytes but ok, revised patch attached. >> > > You can probably get those bytes back by using > if (ut->ut_type == USER_PROCESS) { > printf(" %s" + first, ut->ut_user); > first = 0; > } > > Ralf >
wow, thanks. Regards, -- Pere
From ac9981c2ba250379ce0a5a188e274df14bb07c05 Mon Sep 17 00:00:00 2001 From: Pere Orga <[email protected]> Date: Wed, 27 Jul 2011 14:38:58 +0200 Subject: [PATCH] users: new applet Signed-off-by: Pere Orga <[email protected]> --- coreutils/users.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) create mode 100644 coreutils/users.c diff --git a/coreutils/users.c b/coreutils/users.c new file mode 100644 index 0000000..fdf61c0 --- /dev/null +++ b/coreutils/users.c @@ -0,0 +1,41 @@ +/* vi: set sw=4 ts=4: */ +/* + * users - print users currently logged on + * + * Copyright (c) 2011 Pere Orga <[email protected]> + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + */ + +//kbuild:lib-$(CONFIG_USERS) += users.o +//applet:IF_USERS(APPLET(users, BB_DIR_USR_BIN, BB_SUID_DROP)) + +//config:config USERS +//config: bool "users" +//config: default y +//config: depends on FEATURE_UTMP +//config: help +//config: Print users currently logged on. + +//usage:#define users_trivial_usage +//usage: "" +//usage:#define users_full_usage "\n\n" +//usage: "Print the users currently logged on" + +#include "libbb.h" + +int users_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; +int users_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) +{ + struct utmp *ut; + + int first = 1; + while ((ut = getutent())) { + if (ut->ut_type == USER_PROCESS) { + printf(" %s" + first, ut->ut_user); + first = 0; + } + } + bb_putchar('\n'); + + return EXIT_SUCCESS; +} -- 1.7.2.5
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
