summaryrefslogtreecommitdiff
path: root/usr.bin/less
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-11-07 18:07:45 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-11-07 18:07:45 +0000
commitf1dd1d762ffde115bfddd348133de0608a61c4f2 (patch)
tree2c7cbfb7e414a0c2ec6216b0e1bce4b76eeab1d3 /usr.bin/less
parent4f58b634f741e84de358032badb438c41ffdb1ed (diff)
replace save() with estrdup() and make estrdup() exit like all the other
ecalloc, etc. functions do. ok mmcc nicm
Diffstat (limited to 'usr.bin/less')
-rw-r--r--usr.bin/less/cmdbuf.c4
-rw-r--r--usr.bin/less/command.c2
-rw-r--r--usr.bin/less/decode.c4
-rw-r--r--usr.bin/less/edit.c2
-rw-r--r--usr.bin/less/filename.c4
-rw-r--r--usr.bin/less/funcs.h1
-rw-r--r--usr.bin/less/ifile.c2
-rw-r--r--usr.bin/less/lsystem.c6
-rw-r--r--usr.bin/less/main.c23
-rw-r--r--usr.bin/less/optfunc.c2
-rw-r--r--usr.bin/less/option.c2
-rw-r--r--usr.bin/less/prompt.c12
-rw-r--r--usr.bin/less/tags.c4
13 files changed, 28 insertions, 40 deletions
diff --git a/usr.bin/less/cmdbuf.c b/usr.bin/less/cmdbuf.c
index b055f75b593..2a942488b5d 100644
--- a/usr.bin/less/cmdbuf.c
+++ b/usr.bin/less/cmdbuf.c
@@ -688,7 +688,7 @@ cmd_addhist(struct mlist *mlist, const char *cmd)
* Save the command and put it at the end of the history list.
*/
ml = ecalloc(1, sizeof (struct mlist));
- ml->string = save(cmd);
+ ml->string = estrdup(cmd);
ml->next = mlist;
ml->prev = mlist->prev;
mlist->prev->next = ml;
@@ -1207,7 +1207,7 @@ histfile_name(void)
if (strcmp(name, "-") == 0 || strcmp(name, "/dev/null") == 0)
/* $LESSHISTFILE == "-" means don't use history file */
return (NULL);
- return (save(name));
+ return (estrdup(name));
}
/* Otherwise, file is in $HOME if enabled. */
diff --git a/usr.bin/less/command.c b/usr.bin/less/command.c
index 2487a87507e..fd53eb5e16b 100644
--- a/usr.bin/less/command.c
+++ b/usr.bin/less/command.c
@@ -203,7 +203,7 @@ exec_mca(void)
if (*cbuf == '\0')
every_first_cmd = NULL;
else
- every_first_cmd = save(cbuf);
+ every_first_cmd = estrdup(cbuf);
break;
case A_OPT_TOGGLE:
toggle_option(curropt, opt_lower, cbuf, optflag);
diff --git a/usr.bin/less/decode.c b/usr.bin/less/decode.c
index 50e1da8da8f..66b116e7469 100644
--- a/usr.bin/less/decode.c
+++ b/usr.bin/less/decode.c
@@ -680,9 +680,9 @@ add_hometable(char *envname, char *def_filename, int sysvar)
PARG parg;
if (envname != NULL && (filename = lgetenv(envname)) != NULL)
- filename = save(filename);
+ filename = estrdup(filename);
else if (sysvar)
- filename = save(def_filename);
+ filename = estrdup(def_filename);
else
filename = homefile(def_filename);
if (filename == NULL)
diff --git a/usr.bin/less/edit.c b/usr.bin/less/edit.c
index 8c7ef8b97d1..2f2c507f851 100644
--- a/usr.bin/less/edit.c
+++ b/usr.bin/less/edit.c
@@ -232,7 +232,7 @@ edit_ifile(IFILE ifile)
return (0);
}
- filename = save(get_filename(ifile));
+ filename = estrdup(get_filename(ifile));
/*
* See if LESSOPEN specifies an "alternate" file to open.
*/
diff --git a/usr.bin/less/filename.c b/usr.bin/less/filename.c
index 2a8002865d6..86ea1150cec 100644
--- a/usr.bin/less/filename.c
+++ b/usr.bin/less/filename.c
@@ -643,14 +643,14 @@ open_altfile(char *filename, int *pf, void **pfd)
if (returnfd > 1 && status == 0) {
*pfd = NULL;
*pf = -1;
- return (save(FAKE_EMPTYFILE));
+ return (estrdup(FAKE_EMPTYFILE));
}
return (NULL);
}
ch_ungetchar(c);
*pfd = (void *) fd;
*pf = f;
- return (save("-"));
+ return (estrdup("-"));
}
cmd = readfd(fd);
pclose(fd);
diff --git a/usr.bin/less/funcs.h b/usr.bin/less/funcs.h
index 6a2c69f81fb..95f610b3275 100644
--- a/usr.bin/less/funcs.h
+++ b/usr.bin/less/funcs.h
@@ -9,7 +9,6 @@
struct mlist;
struct loption;
-extern char *save(const char *);
extern void *ecalloc(int, unsigned int);
/*PRINTFLIKE1*/
extern char *easprintf(const char *, ...);
diff --git a/usr.bin/less/ifile.c b/usr.bin/less/ifile.c
index b93a94de502..0675047df0f 100644
--- a/usr.bin/less/ifile.c
+++ b/usr.bin/less/ifile.c
@@ -107,7 +107,7 @@ new_ifile(char *filename, struct ifile *prev)
* Allocate and initialize structure.
*/
p = ecalloc(1, sizeof (struct ifile));
- p->h_filename = save(filename);
+ p->h_filename = estrdup(filename);
p->h_scrpos.pos = -1;
p->h_opened = 0;
p->h_hold = 0;
diff --git a/usr.bin/less/lsystem.c b/usr.bin/less/lsystem.c
index 13cd47ac067..6e19fb7eee1 100644
--- a/usr.bin/less/lsystem.c
+++ b/usr.bin/less/lsystem.c
@@ -85,7 +85,7 @@ lsystem(const char *cmd, const char *donemsg)
p = NULL;
if ((shell = lgetenv("SHELL")) != NULL && *shell != '\0') {
if (*cmd == '\0') {
- p = save(shell);
+ p = estrdup(shell);
} else {
char *esccmd = shell_quote(cmd);
if (esccmd != NULL) {
@@ -96,9 +96,9 @@ lsystem(const char *cmd, const char *donemsg)
}
if (p == NULL) {
if (*cmd == '\0')
- p = save("sh");
+ p = estrdup("sh");
else
- p = save(cmd);
+ p = estrdup(cmd);
}
(void) system(p);
free(p);
diff --git a/usr.bin/less/main.c b/usr.bin/less/main.c
index 7f5f28b33ec..f66beb81c90 100644
--- a/usr.bin/less/main.c
+++ b/usr.bin/less/main.c
@@ -107,7 +107,7 @@ main(int argc, char *argv[])
s = lgetenv(less_is_more ? "MORE" : "LESS");
if (s != NULL)
- scan_option(save(s));
+ scan_option(estrdup(s));
if (less_is_more) {
/* this is specified by XPG */
@@ -257,20 +257,6 @@ main(int argc, char *argv[])
}
/*
- * Copy a string to a "safe" place
- * (that is, to a buffer allocated by calloc).
- */
-char *
-save(const char *s)
-{
- char *p;
-
- if ((p = estrdup(s)) == NULL)
- quit(QUIT_ERROR);
- return (p);
-}
-
-/*
* Allocate memory.
* Like calloc(), but never returns an error (NULL).
*/
@@ -310,9 +296,12 @@ easprintf(const char *fmt, ...)
char *
estrdup(const char *str)
{
- char *n = strdup(str);
- if (n == NULL && str != NULL) {
+ char *n;
+
+ n = strdup(str);
+ if (n == NULL) {
error("Cannot allocate memory", NULL_PARG);
+ quit(QUIT_ERROR);
}
return (n);
}
diff --git a/usr.bin/less/optfunc.c b/usr.bin/less/optfunc.c
index cefe0246fbf..d522f6424e8 100644
--- a/usr.bin/less/optfunc.c
+++ b/usr.bin/less/optfunc.c
@@ -347,7 +347,7 @@ opt__P(int type, char *s)
default: proto = &prproto[PR_SHORT]; break;
}
free(*proto);
- *proto = save(s);
+ *proto = estrdup(s);
break;
case QUERY:
parg.p_string = prproto[pr_type];
diff --git a/usr.bin/less/option.c b/usr.bin/less/option.c
index 6c291a6202e..7bae2b0b6c1 100644
--- a/usr.bin/less/option.c
+++ b/usr.bin/less/option.c
@@ -151,7 +151,7 @@ scan_option(char *s)
if (s == NULL)
return;
if (*str == '+')
- every_first_cmd = save(str+1);
+ every_first_cmd = estrdup(str+1);
else
ungetsc(str);
free(str);
diff --git a/usr.bin/less/prompt.c b/usr.bin/less/prompt.c
index 11983625fc7..58c29f57edc 100644
--- a/usr.bin/less/prompt.c
+++ b/usr.bin/less/prompt.c
@@ -75,12 +75,12 @@ static char *mp;
void
init_prompt(void)
{
- prproto[0] = save(s_proto);
- prproto[1] = save(less_is_more ? more_proto : m_proto);
- prproto[2] = save(less_is_more ? more_M_proto : M_proto);
- eqproto = save(e_proto);
- hproto = save(h_proto);
- wproto = save(w_proto);
+ prproto[0] = estrdup(s_proto);
+ prproto[1] = estrdup(less_is_more ? more_proto : m_proto);
+ prproto[2] = estrdup(less_is_more ? more_M_proto : M_proto);
+ eqproto = estrdup(e_proto);
+ hproto = estrdup(h_proto);
+ wproto = estrdup(w_proto);
}
/*
diff --git a/usr.bin/less/tags.c b/usr.bin/less/tags.c
index 023c8e3fd6c..93f75f21c25 100644
--- a/usr.bin/less/tags.c
+++ b/usr.bin/less/tags.c
@@ -112,13 +112,13 @@ maketagent(char *file, LINENUM linenum, char *pattern, int endline)
struct tag *tp;
tp = ecalloc(sizeof (struct tag), 1);
- tp->tag_file = save(file);
+ tp->tag_file = estrdup(file);
tp->tag_linenum = linenum;
tp->tag_endline = endline;
if (pattern == NULL)
tp->tag_pattern = NULL;
else
- tp->tag_pattern = save(pattern);
+ tp->tag_pattern = estrdup(pattern);
return (tp);
}