summaryrefslogtreecommitdiffstats
path: root/lib/libedit/search.c
diff options
context:
space:
mode:
authormsmith <msmith@FreeBSD.org>1997-06-25 08:14:24 +0000
committermsmith <msmith@FreeBSD.org>1997-06-25 08:14:24 +0000
commitf4312c45dc5fb1b4831e63087e8563fa0fa4601f (patch)
treebfe4a6c5e19e7694273d28cb1b36a820a5ebad0d /lib/libedit/search.c
parentd2cf9d630277a4d4f8601691fb1ac28b727e417e (diff)
downloadFreeBSD-src-f4312c45dc5fb1b4831e63087e8563fa0fa4601f.zip
FreeBSD-src-f4312c45dc5fb1b4831e63087e8563fa0fa4601f.tar.gz
Update libedit with changes from NetBSD. Includes history load/save,
some buffer overflow guards and some stylistic cleanups. Also adds manpages. Obtained from: NetBSD
Diffstat (limited to 'lib/libedit/search.c')
-rw-r--r--lib/libedit/search.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index bf6099d..508835e 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -43,14 +43,11 @@ static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
*/
#include "sys.h"
#include <stdlib.h>
-#ifdef REGEXEC
-#include <sys/types.h>
+#if defined(REGEX)
#include <regex.h>
-#else
-#ifdef REGEXP
+#elif defined(REGEXP)
#include <regexp.h>
#endif
-#endif
#include "el.h"
/*
@@ -107,39 +104,41 @@ el_match(str, pat)
const char *str;
const char *pat;
{
-#ifdef REGEXEC
+#if defined (REGEX)
regex_t re;
-#else
-#ifndef REGEXP
+ int rv;
+#elif defined (REGEXP)
+ regexp *rp;
+ int rv;
+#else
extern char *re_comp __P((const char *));
extern int re_exec __P((const char *));
-#else
- regexp *re;
- int rv;
-#endif
#endif
if (strstr(str, pat) != NULL)
return 1;
-#ifdef REGEXEC
- if (regcomp(&re, pat, REG_EXTENDED | REG_NOSUB) != 0)
- return 0;
- return (regexec(&re, str, 0, NULL, 0) == 0);
-#else
-#ifndef REGEXP
- if (re_comp(pat) != NULL)
- return 0;
- else
- return re_exec(str) == 1;
-#else
+
+#if defined(REGEX)
+ if (regcomp(&re, pat, 0) == 0) {
+ rv = regexec(&re, str, 0, NULL, 0) == 0;
+ regfree(&re);
+ } else {
+ rv = 0;
+ }
+ return rv;
+#elif defined(REGEXP)
if ((re = regcomp(pat)) != NULL) {
rv = regexec(re, str);
free((ptr_t) re);
- }
- else
+ } else {
rv = 0;
+ }
return rv;
-#endif
+#else
+ if (re_comp(pat) != NULL)
+ return 0;
+ else
+ return re_exec(str) == 1;
#endif
}
@@ -462,10 +461,11 @@ cv_search(el, dir)
}
#ifdef ANCHOR
if (el->el_search.patbuf[0] != '.' && el->el_search.patbuf[0] != '*') {
- (void) strcpy(tmpbuf, el->el_search.patbuf);
+ (void)strncpy(tmpbuf, el->el_search.patbuf, sizeof(tmpbuf) - 1);
el->el_search.patbuf[0] = '.';
el->el_search.patbuf[1] = '*';
- (void) strcpy(&el->el_search.patbuf[2], tmpbuf);
+ (void)strncpy(&el->el_search.patbuf[2], tmpbuf,
+ sizeof(el->el_search.patbuf) - 3);
el->el_search.patlen++;
el->el_search.patbuf[el->el_search.patlen++] = '.';
el->el_search.patbuf[el->el_search.patlen++] = '*';
@@ -479,7 +479,8 @@ cv_search(el, dir)
tmpbuf[tmplen++] = '*';
#endif
tmpbuf[tmplen] = '\0';
- (void) strcpy(el->el_search.patbuf, tmpbuf);
+ (void)strncpy(el->el_search.patbuf, tmpbuf,
+ sizeof(el->el_search.patbuf) - 1);
el->el_search.patlen = tmplen;
}
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
OpenPOWER on IntegriCloud