blob: aee898d22d8bd48b61a6dffad2dff867a095c05f [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Denis Vlasenkodb12d1d2008-12-07 00:52:58 +00002/*
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003 * Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenkodb12d1d2008-12-07 00:52:58 +00004 */
Manuel Novoa III cad53642003-03-19 09:13:01 +00005
6/* BB_AUDIT SUSv3 N/A -- Apparently a busybox (obsolete?) extension. */
7
Pere Orga6a3e01d2011-04-01 22:56:30 +02008//usage:#define length_trivial_usage
9//usage: "STRING"
10//usage:#define length_full_usage "\n\n"
11//usage: "Print STRING's length"
12//usage:
13//usage:#define length_example_usage
14//usage: "$ length Hello\n"
15//usage: "5\n"
16
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000017#include "libbb.h"
Eric Andersencc8ed391999-10-05 16:24:54 +000018
Denis Vlasenko99912ca2007-04-10 15:43:37 +000019/* This is a NOFORK applet. Be very careful! */
20
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000021int length_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Rob Landleydfba7412006-03-06 20:47:33 +000022int length_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000023{
Denis Vlasenko99912ca2007-04-10 15:43:37 +000024 if ((argc != 2) || (**(++argv) == '-')) {
25 bb_show_usage();
Manuel Novoa III cad53642003-03-19 09:13:01 +000026 }
27
Denis Vlasenko99912ca2007-04-10 15:43:37 +000028 printf("%u\n", (unsigned)strlen(*argv));
Manuel Novoa III cad53642003-03-19 09:13:01 +000029
Denys Vlasenko8131eea2009-11-02 14:19:51 +010030 return fflush_all();
Eric Andersencc8ed391999-10-05 16:24:54 +000031}