[Toybox] [PATCH] Replace index() with strchr().
Georgi Chorbadzhiyski
gf at unixsol.org
Wed Mar 7 07:20:37 PST 2012
POSIX.1-2008 removes the specifications of index() and rindex(),
recommending strchr(3) and strchr(3) instead. This patch also
helps toybox to be compiled with musl libc.
---
kconfig/lxdialog/util.c | 4 ++--
lib/lib.c | 2 +-
toys/sort.c | 2 +-
toys/which.c | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/kconfig/lxdialog/util.c b/kconfig/lxdialog/util.c
index ebc781b..14ebc72 100644
--- a/kconfig/lxdialog/util.c
+++ b/kconfig/lxdialog/util.c
@@ -338,7 +338,7 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
newl = 1;
word = tempstr;
while (word && *word) {
- sp = index(word, ' ');
+ sp = strchr(word, ' ');
if (sp)
*sp++ = 0;
@@ -350,7 +350,7 @@ void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
if (wlen > room ||
(newl && wlen < 4 && sp
&& wlen + 1 + strlen(sp) > room
- && (!(sp2 = index(sp, ' '))
+ && (!(sp2 = strchr(sp, ' '))
|| wlen + 1 + (sp2 - sp) > room))) {
cur_y++;
cur_x = x;
diff --git a/lib/lib.c b/lib/lib.c
index cc441f9..a1f4a52 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -390,7 +390,7 @@ struct string_list *find_in_path(char *path, char *filename)
char *cwd = xgetcwd();
for (;;) {
- char *next = path ? index(path, ':') : NULL;
+ char *next = path ? strchr(path, ':') : NULL;
int len = next ? next-path : strlen(path);
struct string_list *rnext;
struct stat st;
diff --git a/toys/sort.c b/toys/sort.c
index fabff69..6f9b93b 100644
--- a/toys/sort.c
+++ b/toys/sort.c
@@ -360,7 +360,7 @@ void sort_main(void)
// Which flag is this?
optlist = toys.which->options;
- temp2 = index(optlist, *temp);
+ temp2 = strchr(optlist, *temp);
flag = (1<<(optlist-temp2+strlen(optlist)-1));
// Was it a flag that can apply to a key?
diff --git a/toys/which.c b/toys/which.c
index 1319836..0ffc725 100644
--- a/toys/which.c
+++ b/toys/which.c
@@ -30,7 +30,7 @@ static int which_in_path(char *filename)
// If they gave us a path, don't worry about $PATH or -a
- if (index(filename, '/')) {
+ if (strchr(filename, '/')) {
// Confirm it has the executable bit set, and it's not a directory.
if (!access(filename, X_OK)) {
struct stat st;
--
1.7.5.1
More information about the Toybox
mailing list