Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 1 | /* 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 Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 8 | */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 9 | #include "libbb.h" |
| 10 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 11 | char* FAST_FUNC skip_whitespace(const char *s) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 12 | { |
Denys Vlasenko | f125b6d | 2009-10-22 19:41:45 +0200 | [diff] [blame] | 13 | /* 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 | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 21 | |
Rob Landley | ea224be | 2006-06-18 20:20:07 +0000 | [diff] [blame] | 22 | return (char *) s; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 23 | } |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 24 | |
Denis Vlasenko | defc1ea | 2008-06-27 02:52:20 +0000 | [diff] [blame] | 25 | char* FAST_FUNC skip_non_whitespace(const char *s) |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 26 | { |
Denys Vlasenko | f125b6d | 2009-10-22 19:41:45 +0200 | [diff] [blame] | 27 | while (*s != '\0' && *s != ' ' && (unsigned char)(*s - 9) > (13 - 9)) |
| 28 | s++; |
Denis Vlasenko | 0de9375 | 2006-12-26 02:51:29 +0000 | [diff] [blame] | 29 | |
| 30 | return (char *) s; |
| 31 | } |
Denys Vlasenko | f8d8aa1 | 2010-04-06 18:50:05 +0200 | [diff] [blame] | 32 | |
| 33 | char* FAST_FUNC skip_dev_pfx(const char *tty_name) |
| 34 | { |
Andy Shevchenko | cc22274 | 2017-11-23 19:49:31 +0200 | [diff] [blame] | 35 | char *unprefixed = is_prefixed_with(tty_name, "/dev/"); |
| 36 | return unprefixed ? unprefixed : (char*)tty_name; |
Denys Vlasenko | f8d8aa1 | 2010-04-06 18:50:05 +0200 | [diff] [blame] | 37 | } |