blob: 37a24d3be632834d1a7671a87aac8723a37a59fd [file] [log] [blame]
Manuel Novoa III cad53642003-03-19 09:13:01 +00001/* vi: set sw=4 ts=4: */
2/*
3 * skip_whitespace implementation for busybox
4 *
5 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Manuel Novoa III cad53642003-03-19 09:13:01 +00008 */
Manuel Novoa III cad53642003-03-19 09:13:01 +00009#include "libbb.h"
10
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000011char* FAST_FUNC skip_whitespace(const char *s)
Manuel Novoa III cad53642003-03-19 09:13:01 +000012{
Denys Vlasenkof125b6d2009-10-22 19:41:45 +020013 /* In POSIX/C locale (the only locale we care about: do we REALLY want
14 * to allow Unicode whitespace in, say, .conf files? nuts!)
15 * isspace is only these chars: "\t\n\v\f\r" and space.
16 * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13.
17 * Use that.
18 */
19 while (*s == ' ' || (unsigned char)(*s - 9) <= (13 - 9))
20 s++;
Manuel Novoa III cad53642003-03-19 09:13:01 +000021
Rob Landleyea224be2006-06-18 20:20:07 +000022 return (char *) s;
Manuel Novoa III cad53642003-03-19 09:13:01 +000023}
Denis Vlasenko0de93752006-12-26 02:51:29 +000024
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000025char* FAST_FUNC skip_non_whitespace(const char *s)
Denis Vlasenko0de93752006-12-26 02:51:29 +000026{
Denys Vlasenkof125b6d2009-10-22 19:41:45 +020027 while (*s != '\0' && *s != ' ' && (unsigned char)(*s - 9) > (13 - 9))
28 s++;
Denis Vlasenko0de93752006-12-26 02:51:29 +000029
30 return (char *) s;
31}
Denys Vlasenkof8d8aa12010-04-06 18:50:05 +020032
33char* FAST_FUNC skip_dev_pfx(const char *tty_name)
34{
Andy Shevchenkocc222742017-11-23 19:49:31 +020035 char *unprefixed = is_prefixed_with(tty_name, "/dev/");
36 return unprefixed ? unprefixed : (char*)tty_name;
Denys Vlasenkof8d8aa12010-04-06 18:50:05 +020037}