From e61ae4ffc82906e6b2c3def74121a014c5580448 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sun, 20 Jul 2014 12:06:52 +0000 Subject: [PATCH] sh: Remove prefix() function. Use strncmp() instead. --- bin/sh/exec.c | 2 +- bin/sh/jobs.c | 5 ++++- bin/sh/mystring.c | 15 --------------- bin/sh/mystring.h | 1 - 4 files changed, 5 insertions(+), 18 deletions(-) diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 1b8d3c7dc22c..c9d4126488e6 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -365,7 +365,7 @@ find_command(const char *name, struct cmdentry *entry, int act, for (;(fullname = padvance(&path, name)) != NULL; stunalloc(fullname)) { idx++; if (pathopt) { - if (prefix("func", pathopt)) { + if (strncmp(pathopt, "func", 4) == 0) { /* handled below */ } else { continue; /* ignore unimplemented options */ diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index af5887e02804..93553c11e5bd 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -562,6 +562,7 @@ getjob_nonotfound(const char *name) { int jobno; struct job *found, *jp; + size_t namelen; pid_t pid; int i; @@ -603,10 +604,12 @@ currentjob: if ((jp = getcurjob(NULL)) == NULL) if (found != NULL) return (found); } else { + namelen = strlen(name); found = NULL; for (jp = jobtab, i = njobs ; --i >= 0 ; jp++) { if (jp->used && jp->nprocs > 0 - && prefix(name + 1, jp->ps[0].cmd)) { + && strncmp(jp->ps[0].cmd, name + 1, + namelen - 1) == 0) { if (found) error("%s: ambiguous", name); found = jp; diff --git a/bin/sh/mystring.c b/bin/sh/mystring.c index de7e9b648958..03ea8bac608c 100644 --- a/bin/sh/mystring.c +++ b/bin/sh/mystring.c @@ -60,21 +60,6 @@ char nullstr[1]; /* zero length string */ */ -/* - * prefix -- see if pfx is a prefix of string. - */ - -int -prefix(const char *pfx, const char *string) -{ - while (*pfx) { - if (*pfx++ != *string++) - return 0; - } - return 1; -} - - /* * Convert a string of digits to an integer, printing an error message on * failure. diff --git a/bin/sh/mystring.h b/bin/sh/mystring.h index 87b76c8acff6..919fc867e7cf 100644 --- a/bin/sh/mystring.h +++ b/bin/sh/mystring.h @@ -35,7 +35,6 @@ #include -int prefix(const char *, const char *); int number(const char *); int is_number(const char *);