3241 Nirbhay Choubey 2011-07-29
WL#5945 : Improve libedit library
Sync with NetBSD CVS head.
modified:
cmd-line-utils/libedit/chared.c
cmd-line-utils/libedit/chartype.c
cmd-line-utils/libedit/el.c
cmd-line-utils/libedit/eln.c
cmd-line-utils/libedit/filecomplete.c
cmd-line-utils/libedit/hist.c
cmd-line-utils/libedit/hist.h
cmd-line-utils/libedit/histedit.h
cmd-line-utils/libedit/history.c
cmd-line-utils/libedit/keymacro.c
cmd-line-utils/libedit/map.c
cmd-line-utils/libedit/read.c
cmd-line-utils/libedit/readline.c
cmd-line-utils/libedit/search.c
cmd-line-utils/libedit/sig.c
cmd-line-utils/libedit/sys.h
cmd-line-utils/libedit/terminal.c
cmd-line-utils/libedit/tokenizer.c
cmd-line-utils/libedit/vi.c
3240 Nirbhay Choubey 2011-07-28
WL#5945 : Improve libedit library
Sync with NetBSD CVS head.
renamed:
cmd-line-utils/libedit/el_term.h => cmd-line-utils/libedit/el_terminal.h
cmd-line-utils/libedit/key.c => cmd-line-utils/libedit/keymacro.c
cmd-line-utils/libedit/key.h => cmd-line-utils/libedit/keymacro.h
cmd-line-utils/libedit/term.c => cmd-line-utils/libedit/terminal.c
modified:
cmd-line-utils/libedit/CMakeLists.txt
cmd-line-utils/libedit/README
cmd-line-utils/libedit/chared.c
cmd-line-utils/libedit/chartype.c
cmd-line-utils/libedit/common.c
cmd-line-utils/libedit/el.c
cmd-line-utils/libedit/el.h
cmd-line-utils/libedit/eln.c
cmd-line-utils/libedit/emacs.c
cmd-line-utils/libedit/filecomplete.c
cmd-line-utils/libedit/map.c
cmd-line-utils/libedit/parse.c
cmd-line-utils/libedit/prompt.c
cmd-line-utils/libedit/read.c
cmd-line-utils/libedit/readline.c
cmd-line-utils/libedit/refresh.c
cmd-line-utils/libedit/search.c
cmd-line-utils/libedit/sig.c
cmd-line-utils/libedit/sys.h
cmd-line-utils/libedit/tty.c
cmd-line-utils/libedit/vi.c
cmd-line-utils/libedit/el_terminal.h
cmd-line-utils/libedit/keymacro.c
cmd-line-utils/libedit/keymacro.h
cmd-line-utils/libedit/terminal.c
=== modified file 'cmd-line-utils/libedit/chared.c'
--- a/cmd-line-utils/libedit/chared.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/chared.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chared.c,v 1.30 2011/07/28 01:05:20 christos Exp $ */
+/* $NetBSD: chared.c,v 1.31 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -543,7 +543,7 @@ ch__clearmacro(EditLine *el)
{
c_macro_t *ma = &el->el_chared.c_macro;
while (ma->level >= 0)
- el_free((ptr_t)ma->macro[ma->level--]);
+ el_free(ma->macro[ma->level--]);
}
/* ch_enlargebufs():
@@ -588,7 +588,8 @@ ch_enlargebufs(EditLine *el, size_t addl
/*
* Reallocate kill buffer.
*/
- newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz * sizeof(*newbuffer));
+ newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
+ sizeof(*newbuffer));
if (!newbuffer)
return 0;
@@ -641,20 +642,20 @@ ch_enlargebufs(EditLine *el, size_t addl
protected void
ch_end(EditLine *el)
{
- el_free((ptr_t) el->el_line.buffer);
+ el_free(el->el_line.buffer);
el->el_line.buffer = NULL;
el->el_line.limit = NULL;
- el_free((ptr_t) el->el_chared.c_undo.buf);
+ el_free(el->el_chared.c_undo.buf);
el->el_chared.c_undo.buf = NULL;
- el_free((ptr_t) el->el_chared.c_redo.buf);
+ el_free(el->el_chared.c_redo.buf);
el->el_chared.c_redo.buf = NULL;
el->el_chared.c_redo.pos = NULL;
el->el_chared.c_redo.lim = NULL;
el->el_chared.c_redo.cmd = ED_UNASSIGNED;
- el_free((ptr_t) el->el_chared.c_kill.buf);
+ el_free(el->el_chared.c_kill.buf);
el->el_chared.c_kill.buf = NULL;
ch_reset(el, 1);
- el_free((ptr_t) el->el_chared.c_macro.macro);
+ el_free(el->el_chared.c_macro.macro);
el->el_chared.c_macro.macro = NULL;
}
=== modified file 'cmd-line-utils/libedit/chartype.c'
--- a/cmd-line-utils/libedit/chartype.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/chartype.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $ */
+/* $NetBSD: chartype.c,v 1.7 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -51,7 +51,7 @@ ct_conv_buff_resize(ct_buffer_t *conv, s
void *p;
if (mincsize > conv->csize) {
conv->csize = mincsize;
- p = el_realloc(conv->cbuff, conv->csize * sizeof(char));
+ p = el_realloc(conv->cbuff, conv->csize * sizeof(*conv->cbuff));
if (p == NULL) {
conv->csize = 0;
el_free(conv->cbuff);
@@ -62,7 +62,7 @@ ct_conv_buff_resize(ct_buffer_t *conv, s
if (minwsize > conv->wsize) {
conv->wsize = minwsize;
- p = el_realloc(conv->wbuff, conv->wsize * sizeof(Char));
+ p = el_realloc(conv->wbuff, conv->wsize * sizeof(*conv->wbuff));
if (p == NULL) {
conv->wsize = 0;
el_free(conv->wbuff);
=== modified file 'cmd-line-utils/libedit/el.c'
--- a/cmd-line-utils/libedit/el.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/el.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: el.c,v 1.66 2011/07/28 01:56:27 christos Exp $ */
+/* $NetBSD: el.c,v 1.67 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -59,7 +59,7 @@ static char sccsid[] = "@(#)el.c 8.2 (Be
public EditLine *
el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
{
- EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
+ EditLine *el = el_malloc(sizeof(*el));
if (el == NULL)
return (NULL);
@@ -133,14 +133,14 @@ el_end(EditLine *el)
prompt_end(el);
sig_end(el);
- el_free((ptr_t) el->el_prog);
+ el_free(el->el_prog);
#ifdef WIDECHAR
- el_free((ptr_t) el->el_scratch.cbuff);
- el_free((ptr_t) el->el_scratch.wbuff);
- el_free((ptr_t) el->el_lgcyconv.cbuff);
- el_free((ptr_t) el->el_lgcyconv.wbuff);
+ el_free(el->el_scratch.cbuff);
+ el_free(el->el_scratch.wbuff);
+ el_free(el->el_lgcyconv.cbuff);
+ el_free(el->el_lgcyconv.wbuff);
#endif
- el_free((ptr_t) el);
+ el_free(el);
}
@@ -269,7 +269,7 @@ FUN(el,set)(EditLine *el, int op, ...)
case EL_HIST:
{
hist_fun_t func = va_arg(ap, hist_fun_t);
- ptr_t ptr = va_arg(ap, ptr_t);
+ void *ptr = va_arg(ap, void *);
rv = hist_set(el, func, ptr);
if (!(el->el_flags & CHARSET_IS_UTF8))
@@ -531,7 +531,7 @@ el_source(EditLine *el, const char *fnam
if ((ptr = getenv("HOME")) == NULL)
return (-1);
plen += strlen(ptr);
- if ((path = malloc(plen)) == NULL)
+ if ((path = el_malloc(plen * sizeof(*path))) == NULL)
return (-1);
(void)snprintf(path, plen, "%s%s", ptr, elpath);
fname = path;
=== modified file 'cmd-line-utils/libedit/eln.c'
--- a/cmd-line-utils/libedit/eln.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/eln.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: eln.c,v 1.11 2011/07/28 01:05:20 christos Exp $ */
+/* $NetBSD: eln.c,v 1.12 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -214,7 +214,7 @@ el_set(EditLine *el, int op, ...)
}
case EL_HIST: { /* hist_fun_t, const char * */
hist_fun_t fun = va_arg(ap, hist_fun_t);
- ptr_t ptr = va_arg(ap, ptr_t);
+ void *ptr = va_arg(ap, void *);
ret = hist_set(el, fun, ptr);
el->el_flags |= NARROW_HISTORY;
break;
=== modified file 'cmd-line-utils/libedit/filecomplete.c'
--- a/cmd-line-utils/libedit/filecomplete.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/filecomplete.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: filecomplete.c,v 1.24 2011/07/28 00:50:23 christos Exp $ */
+/* $NetBSD: filecomplete.c,v 1.26 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -95,14 +95,13 @@ static const Char break_chars[] = { ' ',
char *
fn_tilde_expand(const char *txt)
{
- struct passwd *pass;
- char *temp;
- size_t len = 0;
-
#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
struct passwd pwres;
char pwbuf[1024];
#endif
+ struct passwd *pass;
+ char *temp;
+ size_t len = 0;
if (txt[0] != '~')
return (strdup(txt));
@@ -114,7 +113,7 @@ fn_tilde_expand(const char *txt)
return NULL;
} else {
len = temp - txt + 1; /* text until string after slash */
- temp = malloc(len);
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
(void)strncpy(temp, txt + 1, len - 2);
@@ -140,7 +139,7 @@ fn_tilde_expand(const char *txt)
pass = getpwnam(temp);
#endif
}
- free(temp); /* value no more needed */
+ el_free(temp); /* value no more needed */
if (pass == NULL)
return (strdup(txt));
@@ -148,10 +147,11 @@ fn_tilde_expand(const char *txt)
/* first slash */
txt += len;
- temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
+ len = strlen(pass->pw_dir) + 1 + strlen(txt) + 1;
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
- (void)sprintf(temp, "%s/%s", pass->pw_dir, txt);
+ (void)snprintf(temp, len, "%s/%s", pass->pw_dir, txt);
return (temp);
}
@@ -179,9 +179,10 @@ fn_filename_completion_function(const ch
if (temp) {
char *nptr;
temp++;
- nptr = realloc(filename, strlen(temp) + 1);
+ nptr = el_realloc(filename, (strlen(temp) + 1) *
+ sizeof(*nptr));
if (nptr == NULL) {
- free(filename);
+ el_free(filename);
filename = NULL;
return NULL;
}
@@ -189,9 +190,10 @@ fn_filename_completion_function(const ch
(void)strcpy(filename, temp);
len = temp - text; /* including last slash */
- nptr = realloc(dirname, len + 1);
+ nptr = el_realloc(dirname, (len + 1) *
+ sizeof(*nptr));
if (nptr == NULL) {
- free(dirname);
+ el_free(dirname);
dirname = NULL;
return NULL;
}
@@ -199,7 +201,7 @@ fn_filename_completion_function(const ch
(void)strncpy(dirname, text, len);
dirname[len] = '\0';
} else {
- free(filename);
+ el_free(filename);
if (*text == 0)
filename = NULL;
else {
@@ -207,7 +209,7 @@ fn_filename_completion_function(const ch
if (filename == NULL)
return NULL;
}
- free(dirname);
+ el_free(dirname);
dirname = NULL;
}
@@ -218,7 +220,7 @@ fn_filename_completion_function(const ch
/* support for ``~user'' syntax */
- free(dirpath);
+ el_free(dirpath);
dirpath = NULL;
if (dirname == NULL) {
if ((dirname = strdup("")) == NULL)
@@ -269,10 +271,11 @@ fn_filename_completion_function(const ch
len = strlen(entry->d_name);
#endif
- temp = malloc(strlen(dirname) + len + 1);
+ len = strlen(dirname) + len + 1;
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
- (void)sprintf(temp, "%s%s", dirname, entry->d_name);
+ (void)snprintf(temp, len, "%s%s", dirname, entry->d_name);
} else {
(void)closedir(dir);
dir = NULL;
@@ -296,7 +299,7 @@ append_char_function(const char *name)
rs = "/";
out:
if (expname)
- free(expname);
+ el_free(expname);
return rs;
}
/*
@@ -319,10 +322,10 @@ completion_matches(const char *text, cha
char **nmatch_list;
while (matches + 3 >= match_list_len)
match_list_len <<= 1;
- nmatch_list = realloc(match_list,
- match_list_len * sizeof(char *));
+ nmatch_list = el_realloc(match_list,
+ match_list_len * sizeof(*nmatch_list));
if (nmatch_list == NULL) {
- free(match_list);
+ el_free(match_list);
return NULL;
}
match_list = nmatch_list;
@@ -345,9 +348,9 @@ completion_matches(const char *text, cha
max_equal = i;
}
- retstr = malloc(max_equal + 1);
+ retstr = el_malloc((max_equal + 1) * sizeof(*retstr));
if (retstr == NULL) {
- free(match_list);
+ el_free(match_list);
return NULL;
}
(void)strncpy(retstr, match_list[1], max_equal);
@@ -469,9 +472,9 @@ fn_complete(EditLine *el,
len = li->cursor - ctemp;
#if defined(__SSP__) || defined(__SSP_ALL__)
- temp = malloc(sizeof(*temp) * (len + 1));
+ temp = el_malloc((len + 1) * sizeof(*temp));
#else
- temp = alloca(sizeof(*temp) * (len + 1));
+ temp = alloca((len + 1) * sizeof(*temp));
#endif
(void)Strncpy(temp, ctemp, len);
temp[len] = '\0';
@@ -583,12 +586,12 @@ fn_complete(EditLine *el,
/* free elements of array and the array itself */
for (i = 0; matches[i]; i++)
- free(matches[i]);
- free(matches);
+ el_free(matches[i]);
+ el_free(matches);
matches = NULL;
}
#if defined(__SSP__) || defined(__SSP_ALL__)
- free(temp);
+ el_free(temp);
#endif
return retval;
}
=== modified file 'cmd-line-utils/libedit/hist.c'
--- a/cmd-line-utils/libedit/hist.c 2011-05-13 08:32:47 +0000
+++ b/cmd-line-utils/libedit/hist.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hist.c,v 1.17 2009/12/30 23:54:52 christos Exp $ */
+/* $NetBSD: hist.c,v 1.19 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -71,7 +71,7 @@ protected void
hist_end(EditLine *el)
{
- el_free((ptr_t) el->el_history.buf);
+ el_free(el->el_history.buf);
el->el_history.buf = NULL;
}
@@ -80,7 +80,7 @@ hist_end(EditLine *el)
* Set new history interface
*/
protected int
-hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
+hist_set(EditLine *el, hist_fun_t fun, void *ptr)
{
el->el_history.ref = ptr;
@@ -157,7 +157,7 @@ hist_command(EditLine *el, int argc, con
{
const Char *str;
int num;
- HistEvent ev;
+ TYPE(HistEvent) ev;
if (el->el_history.ref == NULL)
return (-1);
@@ -177,10 +177,10 @@ hist_command(EditLine *el, int argc, con
num = (int)Strtol(argv[2], NULL, 0);
if (Strcmp(argv[1], STR("size")) == 0)
- return history(el->el_history.ref, &ev, H_SETSIZE, num);
+ return FUNW(history)(el->el_history.ref, &ev, H_SETSIZE, num);
if (Strcmp(argv[1], STR("unique")) == 0)
- return history(el->el_history.ref, &ev, H_SETUNIQUE, num);
+ return FUNW(history)(el->el_history.ref, &ev, H_SETUNIQUE, num);
return -1;
}
@@ -211,7 +211,7 @@ hist_enlargebuf(EditLine *el, size_t old
#ifdef WIDECHAR
protected wchar_t *
-hist_convert(EditLine *el, int fn, ptr_t arg)
+hist_convert(EditLine *el, int fn, void *arg)
{
HistEventW ev;
if ((*(el)->el_history.fun)((el)->el_history.ref, &ev, fn, arg) == -1)
=== modified file 'cmd-line-utils/libedit/hist.h'
--- a/cmd-line-utils/libedit/hist.h 2011-05-13 08:32:47 +0000
+++ b/cmd-line-utils/libedit/hist.h 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hist.h,v 1.12 2009/12/30 23:54:52 christos Exp $ */
+/* $NetBSD: hist.h,v 1.13 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -42,14 +42,14 @@
#include "histedit.h"
-typedef int (*hist_fun_t)(ptr_t, TYPE(HistEvent) *, int, ...);
+typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
typedef struct el_history_t {
Char *buf; /* The history buffer */
size_t sz; /* Size of history buffer */
Char *last; /* The last character */
int eventno; /* Event we are looking for */
- ptr_t ref; /* Argument for history fcns */
+ void * ref; /* Argument for history fcns */
hist_fun_t fun; /* Event access */
TYPE(HistEvent) ev; /* Event cookie */
} el_history_t;
@@ -77,11 +77,11 @@ typedef struct el_history_t {
protected int hist_init(EditLine *);
protected void hist_end(EditLine *);
protected el_action_t hist_get(EditLine *);
-protected int hist_set(EditLine *, hist_fun_t, ptr_t);
+protected int hist_set(EditLine *, hist_fun_t, void *);
protected int hist_command(EditLine *, int, const Char **);
protected int hist_enlargebuf(EditLine *, size_t, size_t);
#ifdef WIDECHAR
-protected wchar_t *hist_convert(EditLine *, int, ptr_t);
+protected wchar_t *hist_convert(EditLine *, int, void *);
#endif
#endif /* _h_el_hist */
=== modified file 'cmd-line-utils/libedit/histedit.h'
--- a/cmd-line-utils/libedit/histedit.h 2011-05-13 08:32:47 +0000
+++ b/cmd-line-utils/libedit/histedit.h 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: histedit.h,v 1.47 2010/08/28 15:44:59 christos Exp $ */
+/* $NetBSD: histedit.h,v 1.48 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -142,7 +142,7 @@ unsigned char _el_fn_complete(EditLine *
#define EL_SETTY 8 /* , const Char *, ..., NULL); set */
#define EL_ADDFN 9 /* , const Char *, const Char, set */
/* el_func_t); */
-#define EL_HIST 10 /* , hist_fun_t, const ptr_t); set */
+#define EL_HIST 10 /* , hist_fun_t, const void *); set */
#define EL_EDITMODE 11 /* , int); set/get */
#define EL_RPROMPT 12 /* , prompt_func); set/get */
#define EL_GETCFN 13 /* , el_rfunc_t); set/get */
=== modified file 'cmd-line-utils/libedit/history.c'
--- a/cmd-line-utils/libedit/history.c 2011-07-27 07:55:09 +0000
+++ b/cmd-line-utils/libedit/history.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: history.c,v 1.39 2011/07/27 02:23:29 christos Exp $ */
+/* $NetBSD: history.c,v 1.42 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -58,13 +58,13 @@ static const char hist_cookie[] = "_HiSt
#include "histedit.h"
#include "chartype.h"
-typedef int (*history_gfun_t)(ptr_t, TYPE(HistEvent) *);
-typedef int (*history_efun_t)(ptr_t, TYPE(HistEvent) *, const Char *);
-typedef void (*history_vfun_t)(ptr_t, TYPE(HistEvent) *);
-typedef int (*history_sfun_t)(ptr_t, TYPE(HistEvent) *, const int);
+typedef int (*history_gfun_t)(void *, TYPE(HistEvent) *);
+typedef int (*history_efun_t)(void *, TYPE(HistEvent) *, const Char *);
+typedef void (*history_vfun_t)(void *, TYPE(HistEvent) *);
+typedef int (*history_sfun_t)(void *, TYPE(HistEvent) *, const int);
struct TYPE(history) {
- ptr_t h_ref; /* Argument for history fcns */
+ void *h_ref; /* Argument for history fcns */
int h_ent; /* Last entry point for history */
history_gfun_t h_first; /* Get the first element */
history_gfun_t h_next; /* Get the next element */
@@ -136,23 +136,23 @@ typedef struct history_t {
#define H_UNIQUE 1 /* Store only unique elements */
} history_t;
-private int history_def_next(ptr_t, TYPE(HistEvent) *);
-private int history_def_first(ptr_t, TYPE(HistEvent) *);
-private int history_def_prev(ptr_t, TYPE(HistEvent) *);
-private int history_def_last(ptr_t, TYPE(HistEvent) *);
-private int history_def_curr(ptr_t, TYPE(HistEvent) *);
-private int history_def_set(ptr_t, TYPE(HistEvent) *, const int);
-private void history_def_clear(ptr_t, TYPE(HistEvent) *);
-private int history_def_enter(ptr_t, TYPE(HistEvent) *, const Char *);
-private int history_def_add(ptr_t, TYPE(HistEvent) *, const Char *);
-private int history_def_del(ptr_t, TYPE(HistEvent) *, const int);
+private int history_def_next(void *, TYPE(HistEvent) *);
+private int history_def_first(void *, TYPE(HistEvent) *);
+private int history_def_prev(void *, TYPE(HistEvent) *);
+private int history_def_last(void *, TYPE(HistEvent) *);
+private int history_def_curr(void *, TYPE(HistEvent) *);
+private int history_def_set(void *, TYPE(HistEvent) *, const int);
+private void history_def_clear(void *, TYPE(HistEvent) *);
+private int history_def_enter(void *, TYPE(HistEvent) *, const Char *);
+private int history_def_add(void *, TYPE(HistEvent) *, const Char *);
+private int history_def_del(void *, TYPE(HistEvent) *, const int);
-private int history_def_init(ptr_t *, TYPE(HistEvent) *, int);
+private int history_def_init(void **, TYPE(HistEvent) *, int);
private int history_def_insert(history_t *, TYPE(HistEvent) *, const Char *);
private void history_def_delete(history_t *, TYPE(HistEvent) *, hentry_t *);
private int history_deldata_nth(history_t *, TYPE(HistEvent) *, int, void **);
-private int history_set_nth(ptr_t, TYPE(HistEvent) *, int);
+private int history_set_nth(void *, TYPE(HistEvent) *, int);
#define history_def_setsize(p, num)(void) (((history_t *)p)->max = (num))
#define history_def_getsize(p) (((history_t *)p)->cur)
@@ -210,7 +210,7 @@ static const Char *const he_errlist[] =
* Default function to return the first event in the history.
*/
private int
-history_def_first(ptr_t p, TYPE(HistEvent) *ev)
+history_def_first(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -230,7 +230,7 @@ history_def_first(ptr_t p, TYPE(HistEven
* Default function to return the last event in the history.
*/
private int
-history_def_last(ptr_t p, TYPE(HistEvent) *ev)
+history_def_last(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -250,7 +250,7 @@ history_def_last(ptr_t p, TYPE(HistEvent
* Default function to return the next event in the history.
*/
private int
-history_def_next(ptr_t p, TYPE(HistEvent) *ev)
+history_def_next(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -275,7 +275,7 @@ history_def_next(ptr_t p, TYPE(HistEvent
* Default function to return the previous event in the history.
*/
private int
-history_def_prev(ptr_t p, TYPE(HistEvent) *ev)
+history_def_prev(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -301,7 +301,7 @@ history_def_prev(ptr_t p, TYPE(HistEvent
* Default function to return the current event in the history.
*/
private int
-history_def_curr(ptr_t p, TYPE(HistEvent) *ev)
+history_def_curr(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -322,7 +322,7 @@ history_def_curr(ptr_t p, TYPE(HistEvent
* given one.
*/
private int
-history_def_set(ptr_t p, TYPE(HistEvent) *ev, const int n)
+history_def_set(void *p, TYPE(HistEvent) *ev, const int n)
{
history_t *h = (history_t *) p;
@@ -349,7 +349,7 @@ history_def_set(ptr_t p, TYPE(HistEvent)
* n-th one.
*/
private int
-history_set_nth(ptr_t p, TYPE(HistEvent) *ev, int n)
+history_set_nth(void *p, TYPE(HistEvent) *ev, int n)
{
history_t *h = (history_t *) p;
@@ -373,7 +373,7 @@ history_set_nth(ptr_t p, TYPE(HistEvent)
* Append string to element
*/
private int
-history_def_add(ptr_t p, TYPE(HistEvent) *ev, const Char *str)
+history_def_add(void *p, TYPE(HistEvent) *ev, const Char *str)
{
history_t *h = (history_t *) p;
size_t len;
@@ -391,7 +391,7 @@ history_def_add(ptr_t p, TYPE(HistEvent)
(void) Strncpy(s, h->cursor->ev.str, len);
s[len - 1] = '\0';
(void) Strncat(s, str, len - Strlen(s) - 1);
- h_free((ptr_t)evp->str);
+ h_free(evp->str);
evp->str = s;
*ev = h->cursor->ev;
return (0);
@@ -421,7 +421,7 @@ history_deldata_nth(history_t *h, TYPE(H
*/
/* ARGSUSED */
private int
-history_def_del(ptr_t p, TYPE(HistEvent) *ev __attribute__((__unused__)),
+history_def_del(void *p, TYPE(HistEvent) *ev __attribute__((__unused__)),
const int num)
{
history_t *h = (history_t *) p;
@@ -452,7 +452,7 @@ history_def_delete(history_t *h,
}
hp->prev->next = hp->next;
hp->next->prev = hp->prev;
- h_free((ptr_t) evp->str);
+ h_free(evp->str);
h_free(hp);
h->cur--;
}
@@ -470,7 +470,7 @@ history_def_insert(history_t *h, TYPE(Hi
if (c == NULL)
goto oomem;
if ((c->ev.str = h_strdup(str)) == NULL) {
- h_free((ptr_t)c);
+ h_free(c);
goto oomem;
}
c->data = NULL;
@@ -494,7 +494,7 @@ oomem:
* Default function to enter an item in the history
*/
private int
-history_def_enter(ptr_t p, TYPE(HistEvent) *ev, const Char *str)
+history_def_enter(void *p, TYPE(HistEvent) *ev, const Char *str)
{
history_t *h = (history_t *) p;
@@ -521,9 +521,9 @@ history_def_enter(ptr_t p, TYPE(HistEven
*/
/* ARGSUSED */
private int
-history_def_init(ptr_t *p, TYPE(HistEvent) *ev __attribute__((__unused__)), int n)
+history_def_init(void **p, TYPE(HistEvent) *ev __attribute__((__unused__)), int n)
{
- history_t *h = (history_t *) h_malloc(sizeof(history_t));
+ history_t *h = (history_t *) h_malloc(sizeof(*h));
if (h == NULL)
return -1;
@@ -537,7 +537,7 @@ history_def_init(ptr_t *p, TYPE(HistEven
h->list.ev.num = 0;
h->cursor = &h->list;
h->flags = 0;
- *p = (ptr_t) h;
+ *p = h;
return 0;
}
@@ -546,7 +546,7 @@ history_def_init(ptr_t *p, TYPE(HistEven
* Default history cleanup function
*/
private void
-history_def_clear(ptr_t p, TYPE(HistEvent) *ev)
+history_def_clear(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -569,12 +569,12 @@ public TYPE(History) *
FUN(history,init)(void)
{
TYPE(HistEvent) ev;
- TYPE(History) *h = (TYPE(History) *) h_malloc(sizeof(TYPE(History)));
+ TYPE(History) *h = (TYPE(History) *) h_malloc(sizeof(*h));
if (h == NULL)
return NULL;
if (history_def_init(&h->h_ref, &ev, 0) == -1) {
- h_free((ptr_t)h);
+ h_free(h);
return NULL;
}
h->h_ent = -1;
@@ -750,7 +750,7 @@ history_load(TYPE(History) *h, const cha
if (strncmp(line, hist_cookie, sz) != 0)
goto done;
- ptr = h_malloc(max_size = 1024);
+ ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
if (ptr == NULL)
goto done;
for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
@@ -764,7 +764,7 @@ history_load(TYPE(History) *h, const cha
if (max_size < sz) {
char *nptr;
max_size = (sz + 1024) & ~1023;
- nptr = h_realloc(ptr, max_size);
+ nptr = h_realloc(ptr, max_size * sizeof(*ptr));
if (nptr == NULL) {
i = -1;
goto oomem;
@@ -779,7 +779,7 @@ history_load(TYPE(History) *h, const cha
}
}
oomem:
- h_free((ptr_t)ptr);
+ h_free(ptr);
done:
(void) fclose(fp);
return (i);
@@ -796,7 +796,8 @@ history_save(TYPE(History) *h, const cha
TYPE(HistEvent) ev;
int i = -1, retval;
size_t len, max_size;
- char *ptr, *str;
+ char *ptr;
+ const char *str;
#ifdef WIDECHAR
static ct_buffer_t conv;
#endif
@@ -808,7 +809,7 @@ history_save(TYPE(History) *h, const cha
goto done;
if (fputs(hist_cookie, fp) == EOF)
goto done;
- ptr = h_malloc(max_size = 1024);
+ ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
if (ptr == NULL)
goto done;
for (i = 0, retval = HLAST(h, &ev);
@@ -819,7 +820,7 @@ history_save(TYPE(History) *h, const cha
if (len >= max_size) {
char *nptr;
max_size = (len + 1024) & ~1023;
- nptr = h_realloc(ptr, max_size);
+ nptr = h_realloc(ptr, max_size * sizeof(*ptr));
if (nptr == NULL) {
i = -1;
goto oomem;
@@ -830,7 +831,7 @@ history_save(TYPE(History) *h, const cha
(void) fprintf(fp, "%s\n", ptr);
}
oomem:
- h_free((ptr_t)ptr);
+ h_free(ptr);
done:
(void) fclose(fp);
return (i);
@@ -1037,7 +1038,7 @@ FUNW(history)(TYPE(History) *h, TYPE(His
{
TYPE(History) hf;
- hf.h_ref = va_arg(va, ptr_t);
+ hf.h_ref = va_arg(va, void *);
h->h_ent = -1;
hf.h_first = va_arg(va, history_gfun_t);
hf.h_next = va_arg(va, history_gfun_t);
=== modified file 'cmd-line-utils/libedit/keymacro.c'
--- a/cmd-line-utils/libedit/keymacro.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/keymacro.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: keymacro.c,v 1.3 2011/07/28 03:52:19 christos Exp $ */
+/* $NetBSD: keymacro.c,v 1.4 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -119,7 +119,7 @@ protected void
keymacro_end(EditLine *el)
{
- el_free((ptr_t) el->el_keymacro.buf);
+ el_free(el->el_keymacro.buf);
el->el_keymacro.buf = NULL;
node__free(el->el_keymacro.map);
}
@@ -342,7 +342,7 @@ node__try(EditLine *el, keymacro_node_t
case XK_STR:
case XK_EXE:
if (ptr->val.str)
- el_free((ptr_t) ptr->val.str);
+ el_free(ptr->val.str);
break;
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
@@ -443,13 +443,13 @@ node__put(EditLine *el, keymacro_node_t
case XK_EXE:
case XK_STR:
if (ptr->val.str != NULL)
- el_free((ptr_t) ptr->val.str);
+ el_free(ptr->val.str);
break;
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type));
break;
}
- el_free((ptr_t) ptr);
+ el_free(ptr);
}
@@ -461,7 +461,7 @@ node__get(Int ch)
{
keymacro_node_t *ptr;
- ptr = (keymacro_node_t *) el_malloc((size_t) sizeof(keymacro_node_t));
+ ptr = el_malloc(sizeof(*ptr));
if (ptr == NULL)
return NULL;
ptr->ch = ch;
@@ -479,7 +479,7 @@ node__free(keymacro_node_t *k)
return;
node__free(k->sibling);
node__free(k->next);
- el_free((ptr_t) k);
+ el_free(k);
}
/* node_lookup():
=== modified file 'cmd-line-utils/libedit/map.c'
--- a/cmd-line-utils/libedit/map.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/map.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: map.c,v 1.27 2011/07/28 01:56:27 christos Exp $ */
+/* $NetBSD: map.c,v 1.28 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -902,26 +902,25 @@ map_init(EditLine *el)
EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
#endif
- el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ el->el_map.alt = el_malloc(sizeof(*el->el_map.alt) * N_KEYS);
if (el->el_map.alt == NULL)
return (-1);
- el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ el->el_map.key = el_malloc(sizeof(*el->el_map.key) * N_KEYS);
if (el->el_map.key == NULL)
return (-1);
el->el_map.emacs = el_map_emacs;
el->el_map.vic = el_map_vi_command;
el->el_map.vii = el_map_vi_insert;
- el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
- EL_NUM_FCNS);
+ el->el_map.help = el_malloc(sizeof(*el->el_map.help) * EL_NUM_FCNS);
if (el->el_map.help == NULL)
return (-1);
(void) memcpy(el->el_map.help, help__get(),
- sizeof(el_bindings_t) * EL_NUM_FCNS);
- el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
- EL_NUM_FCNS);
+ sizeof(*el->el_map.help) * EL_NUM_FCNS);
+ el->el_map.func = el_malloc(sizeof(*el->el_map.func) * EL_NUM_FCNS);
if (el->el_map.func == NULL)
return (-1);
- memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
+ memcpy(el->el_map.func, func__get(), sizeof(*el->el_map.func)
+ * EL_NUM_FCNS);
el->el_map.nfunc = EL_NUM_FCNS;
#ifdef VIDEFAULT
@@ -940,16 +939,16 @@ protected void
map_end(EditLine *el)
{
- el_free((ptr_t) el->el_map.alt);
+ el_free(el->el_map.alt);
el->el_map.alt = NULL;
- el_free((ptr_t) el->el_map.key);
+ el_free(el->el_map.key);
el->el_map.key = NULL;
el->el_map.emacs = NULL;
el->el_map.vic = NULL;
el->el_map.vii = NULL;
- el_free((ptr_t) el->el_map.help);
+ el_free(el->el_map.help);
el->el_map.help = NULL;
- el_free((ptr_t) el->el_map.func);
+ el_free(el->el_map.func);
el->el_map.func = NULL;
}
@@ -1400,13 +1399,14 @@ map_addfunc(EditLine *el, const Char *na
if (name == NULL || help == NULL || func == NULL)
return (-1);
- if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
+ if ((p = el_realloc(el->el_map.func, nf *
+ sizeof(*el->el_map.func))) == NULL)
return (-1);
- el->el_map.func = (el_func_t *) p;
- if ((p = el_realloc(el->el_map.help, nf * sizeof(el_bindings_t)))
+ el->el_map.func = p;
+ if ((p = el_realloc(el->el_map.help, nf * sizeof(*el->el_map.help)))
== NULL)
return (-1);
- el->el_map.help = (el_bindings_t *) p;
+ el->el_map.help = p;
nf = el->el_map.nfunc;
el->el_map.func[nf] = func;
=== modified file 'cmd-line-utils/libedit/read.c'
--- a/cmd-line-utils/libedit/read.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/read.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.63 2011/07/28 01:56:27 christos Exp $ */
+/* $NetBSD: read.c,v 1.64 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -161,7 +161,7 @@ read__fixio(int fd __attribute__((__unus
{
int zero = 0;
- if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
+ if (ioctl(fd, FIONBIO, &zero) == -1)
return (-1);
else
e = 1;
@@ -195,7 +195,7 @@ read_preread(EditLine *el)
/* FIONREAD attempts to buffer up multiple bytes, and to make that work
* properly with partial wide/UTF-8 characters would need some careful work. */
#ifdef FIONREAD
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
+ (void) ioctl(el->el_infd, FIONREAD, &chrs);
if (chrs > 0) {
char buf[EL_BUFSIZ];
@@ -515,7 +515,7 @@ FUN(el,gets)(EditLine *el, int *nread)
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
long chrs = 0;
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
+ (void) ioctl(el->el_infd, FIONREAD, &chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
errno = 0;
=== modified file 'cmd-line-utils/libedit/readline.c'
--- a/cmd-line-utils/libedit/readline.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/readline.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.93 2011/07/28 00:54:26 christos Exp $ */
+/* $NetBSD: readline.c,v 1.95 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -260,7 +260,7 @@ rl_set_prompt(const char *prompt)
if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0)
return 0;
if (rl_prompt)
- free(rl_prompt);
+ el_free(rl_prompt);
rl_prompt = strdup(prompt);
if (rl_prompt == NULL)
return -1;
@@ -474,7 +474,7 @@ _rl_compat_sub(const char *str, const ch
} else
s++;
}
- r = result = malloc(len + 1);
+ r = result = el_malloc((len + 1) * sizeof(*r));
if (result == NULL)
return NULL;
s = str;
@@ -564,7 +564,7 @@ get_history_event(const char *cmd, int *
else if (len == 0)
return(NULL);
else {
- if ((pat = malloc(len + 1)) == NULL)
+ if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL)
return NULL;
(void)strncpy(pat, cmd + begin, len);
pat[len] = '\0';
@@ -572,7 +572,7 @@ get_history_event(const char *cmd, int *
if (history(h, &ev, H_CURR) != 0) {
if (pat != last_search_pat)
- free(pat);
+ el_free(pat);
return (NULL);
}
num = ev.num;
@@ -580,7 +580,7 @@ get_history_event(const char *cmd, int *
if (sub) {
if (pat != last_search_pat) {
if (last_search_pat)
- free(last_search_pat);
+ el_free(last_search_pat);
last_search_pat = pat;
}
ret = history_search(pat, -1);
@@ -592,18 +592,18 @@ get_history_event(const char *cmd, int *
history(h, &ev, H_FIRST);
(void)fprintf(rl_outstream, "%s: Event not found\n", pat);
if (pat != last_search_pat)
- free(pat);
+ el_free(pat);
return(NULL);
}
if (sub && len) {
if (last_search_match && last_search_match != pat)
- free(last_search_match);
+ el_free(last_search_match);
last_search_match = pat;
}
if (pat != last_search_pat)
- free(pat);
+ el_free(pat);
if (history(h, &ev, H_CURR) != 0)
return(NULL);
@@ -658,7 +658,8 @@ _history_expand_command(const char *comm
} else {
if (command[offs + 1] == '#') {
/* use command so far */
- if ((aptr = malloc(offs + 1)) == NULL)
+ if ((aptr = el_malloc((offs + 1) * sizeof(*aptr)))
+ == NULL)
return -1;
(void)strncpy(aptr, command, offs);
aptr[offs] = '\0';
@@ -678,7 +679,7 @@ _history_expand_command(const char *comm
if (!has_mods) {
*result = strdup(aptr ? aptr : ptr);
if (aptr)
- free(aptr);
+ el_free(aptr);
if (*result == NULL)
return -1;
return(1);
@@ -726,14 +727,14 @@ _history_expand_command(const char *comm
(void)fprintf(rl_outstream, "%s: Bad word specifier",
command + offs + idx);
if (aptr)
- free(aptr);
+ el_free(aptr);
return(-1);
}
} else
tmp = strdup(aptr? aptr:ptr);
if (aptr)
- free(aptr);
+ el_free(aptr);
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) {
*result = tmp;
@@ -749,7 +750,7 @@ _history_expand_command(const char *comm
} else if (*cmd == 't') { /* remove leading path */
if ((aptr = strrchr(tmp, '/')) != NULL) {
aptr = strdup(aptr + 1);
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
} else if (*cmd == 'r') { /* remove trailing suffix */
@@ -758,7 +759,7 @@ _history_expand_command(const char *comm
} else if (*cmd == 'e') { /* remove all but suffix */
if ((aptr = strrchr(tmp, '.')) != NULL) {
aptr = strdup(aptr);
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
} else if (*cmd == 'p') /* print only */
@@ -775,10 +776,10 @@ _history_expand_command(const char *comm
else if (*cmd == 's') {
delim = *(++cmd), cmd++;
size = 16;
- what = realloc(from, size);
+ what = el_realloc(from, size * sizeof(*what));
if (what == NULL) {
- free(from);
- free(tmp);
+ el_free(from);
+ el_free(tmp);
return 0;
}
len = 0;
@@ -787,11 +788,12 @@ _history_expand_command(const char *comm
cmd++;
if (len >= size) {
char *nwhat;
- nwhat = realloc(what,
- (size <<= 1));
+ nwhat = el_realloc(what,
+ (size <<= 1) *
+ sizeof(*nwhat));
if (nwhat == NULL) {
- free(what);
- free(tmp);
+ el_free(what);
+ el_free(tmp);
return 0;
}
what = nwhat;
@@ -801,16 +803,16 @@ _history_expand_command(const char *comm
what[len] = '\0';
from = what;
if (*what == '\0') {
- free(what);
+ el_free(what);
if (search) {
from = strdup(search);
if (from == NULL) {
- free(tmp);
+ el_free(tmp);
return 0;
}
} else {
from = NULL;
- free(tmp);
+ el_free(tmp);
return (-1);
}
}
@@ -819,10 +821,10 @@ _history_expand_command(const char *comm
continue;
size = 16;
- with = realloc(to, size);
+ with = el_realloc(to, size * sizeof(*with));
if (with == NULL) {
- free(to);
- free(tmp);
+ el_free(to);
+ el_free(tmp);
return -1;
}
len = 0;
@@ -831,10 +833,11 @@ _history_expand_command(const char *comm
if (len + from_len + 1 >= size) {
char *nwith;
size += from_len + 1;
- nwith = realloc(with, size);
+ nwith = el_realloc(with,
+ size * sizeof(*nwith));
if (nwith == NULL) {
- free(with);
- free(tmp);
+ el_free(with);
+ el_free(tmp);
return -1;
}
with = nwith;
@@ -857,7 +860,7 @@ _history_expand_command(const char *comm
aptr = _rl_compat_sub(tmp, from, to, g_on);
if (aptr) {
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
g_on = 0;
@@ -889,7 +892,7 @@ history_expand(char *str, char **output)
*output = NULL;
if (str[0] == history_subst_char) {
/* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */
- *output = malloc(strlen(str) + 4 + 1);
+ *output = el_malloc((strlen(str) + 4 + 1) * sizeof(*output));
if (*output == NULL)
return 0;
(*output)[0] = (*output)[1] = history_expansion_char;
@@ -906,11 +909,12 @@ history_expand(char *str, char **output)
#define ADD_STRING(what, len, fr) \
{ \
if (idx + len + 1 > size) { \
- char *nresult = realloc(result, (size += len + 1));\
+ char *nresult = el_realloc(result, \
+ (size += len + 1) * sizeof(*nresult)); \
if (nresult == NULL) { \
- free(*output); \
+ el_free(*output); \
if (/*CONSTCOND*/fr) \
- free(tmp); \
+ el_free(tmp); \
return 0; \
} \
result = nresult; \
@@ -977,7 +981,7 @@ loop:
ADD_STRING(tmp, len, 1);
}
if (tmp) {
- free(tmp);
+ el_free(tmp);
tmp = NULL;
}
i = j;
@@ -994,7 +998,7 @@ loop:
ret = -1;
#endif
}
- free(*output);
+ el_free(*output);
*output = result;
return (ret);
@@ -1035,7 +1039,7 @@ history_arg_extract(int start, int end,
for (i = start, len = 0; i <= (size_t)end; i++)
len += strlen(arr[i]) + 1;
len++;
- result = malloc(len);
+ result = el_malloc(len * sizeof(*result));
if (result == NULL)
goto out;
@@ -1049,8 +1053,8 @@ history_arg_extract(int start, int end,
out:
for (i = 0; arr[i]; i++)
- free(arr[i]);
- free(arr);
+ el_free(arr[i]);
+ el_free(arr);
return result;
}
@@ -1089,19 +1093,19 @@ history_tokenize(const char *str)
if (idx + 2 >= size) {
char **nresult;
size <<= 1;
- nresult = realloc(result, size * sizeof(char *));
+ nresult = el_realloc(result, size * sizeof(*nresult));
if (nresult == NULL) {
- free(result);
+ el_free(result);
return NULL;
}
result = nresult;
}
len = i - start;
- temp = malloc(len + 1);
+ temp = el_malloc((len + 1) * sizeof(*temp));
if (temp == NULL) {
for (i = 0; i < idx; i++)
- free(result[i]);
- free(result);
+ el_free(result[i]);
+ el_free(result);
return NULL;
}
(void)strncpy(temp, &str[start], len);
@@ -1394,11 +1398,11 @@ remove_history(int num)
if (h == NULL || e == NULL)
rl_initialize();
- if ((he = malloc(sizeof(*he))) == NULL)
+ if ((he = el_malloc(sizeof(*he))) == NULL)
return NULL;
if (history(h, &ev, H_DELDATA, num, &he->data) != 0) {
- free(he);
+ el_free(he);
return NULL;
}
@@ -1432,7 +1436,7 @@ replace_history_entry(int num, const cha
if (history(h, &ev, H_LAST) != 0)
return NULL; /* error */
- if ((he = malloc(sizeof(*he))) == NULL)
+ if ((he = el_malloc(sizeof(*he))) == NULL)
return NULL;
/* look forwards for event matching specified offset */
@@ -1452,7 +1456,7 @@ replace_history_entry(int num, const cha
return he;
out:
- free(he);
+ el_free(he);
return NULL;
}
@@ -1672,16 +1676,17 @@ filename_completion_function(const char
* a completion generator for usernames; returns _first_ username
* which starts with supplied text
* text contains a partial username preceded by random character
- * (usually '~'); state is ignored
+ * (usually '~'); state resets search from start (??? should we do that anyway)
* it's callers responsibility to free returned value
*/
char *
username_completion_function(const char *text, int state)
{
-
- /* XXXMYSQL : warning: unused variable ‘pwbuf’ & 'pwres'. */
- struct passwd *pwd;
- //char pwbuf[1024];
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ struct passwd pwres;
+ char pwbuf[1024];
+#endif
+ struct passwd *pass = NULL;
if (text[0] == '\0')
return (NULL);
@@ -1692,15 +1697,21 @@ username_completion_function(const char
if (state == 0)
setpwent();
- /* XXXMYSQL: just use non-_r functions for now */
- while ((pwd = getpwent()) && text[0] == pwd->pw_name[0]
- && strcmp(text, pwd->pw_name) == 0);
+ while (
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pass) == 0 && pass != NULL
+#else
+ (pass = getpwent()) != NULL
+#endif
+ && text[0] == pass->pw_name[0]
+ && strcmp(text, pass->pw_name) == 0)
+ continue;
- if (pwd == NULL) {
+ if (pass == NULL) {
endpwent();
return NULL;
}
- return strdup(pwd->pw_name);
+ return strdup(pass->pw_name);
}
@@ -2110,7 +2121,7 @@ rl_completion_matches(const char *str, r
len = 1;
max = 10;
- if ((list = malloc(max * sizeof(*list))) == NULL)
+ if ((list = el_malloc(max * sizeof(*list))) == NULL)
return NULL;
while ((match = (*fun)(str, (int)(len - 1))) != NULL) {
@@ -2118,7 +2129,7 @@ rl_completion_matches(const char *str, r
if (len == max) {
char **nl;
max += 10;
- if ((nl = realloc(list, max * sizeof(*nl))) == NULL)
+ if ((nl = el_realloc(list, max * sizeof(*nl))) == NULL)
goto out;
list = nl;
}
@@ -2145,7 +2156,7 @@ rl_completion_matches(const char *str, r
if ((list[0] = strdup(str)) == NULL)
goto out;
} else {
- if ((list[0] = malloc(min + 1)) == NULL)
+ if ((list[0] = el_malloc((min + 1) * sizeof(*list[0]))) == NULL)
goto out;
(void)memcpy(list[0], list[1], min);
list[0][min] = '\0';
@@ -2153,7 +2164,7 @@ rl_completion_matches(const char *str, r
return list;
out:
- free(list);
+ el_free(list);
return NULL;
}
@@ -2188,7 +2199,7 @@ history_get_history_state(void)
{
HISTORY_STATE *hs;
- if ((hs = malloc(sizeof(HISTORY_STATE))) == NULL)
+ if ((hs = el_malloc(sizeof(*hs))) == NULL)
return (NULL);
hs->length = history_length;
return (hs);
=== modified file 'cmd-line-utils/libedit/search.c'
--- a/cmd-line-utils/libedit/search.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/search.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: search.c,v 1.25 2011/07/28 00:46:26 christos Exp $ */
+/* $NetBSD: search.c,v 1.26 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -85,7 +85,7 @@ protected void
search_end(EditLine *el)
{
- el_free((ptr_t) el->el_search.patbuf);
+ el_free(el->el_search.patbuf);
el->el_search.patbuf = NULL;
}
@@ -136,7 +136,7 @@ el_match(const Char *str, const Char *pa
#elif defined(REGEXP)
if ((re = regcomp(ct_encode_string(pat, &conv))) != NULL) {
rv = regexec(re, ct_encode_string(str, &conv));
- free((ptr_t) re);
+ el_free(re);
} else {
rv = 0;
}
=== modified file 'cmd-line-utils/libedit/sig.c'
--- a/cmd-line-utils/libedit/sig.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/sig.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sig.c,v 1.16 2011/07/28 00:46:06 christos Exp $ */
+/* $NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -57,15 +57,15 @@ private const int sighdl[] = {
- 1
};
-private void el_sig_handler(int);
+private void sig_handler(int);
-/* el_sig_handler():
+/* sig_handler():
* This is the handler called for all signals
* XXX: we cannot pass any data so we just store the old editline
* state in a private variable
*/
private void
-el_sig_handler(int signo)
+sig_handler(int signo)
{
int i;
sigset_t nset, oset;
@@ -145,7 +145,7 @@ protected void
sig_end(EditLine *el)
{
- el_free((ptr_t) el->el_signal);
+ el_free(el->el_signal);
el->el_signal = NULL;
}
@@ -160,7 +160,7 @@ sig_set(EditLine *el)
sigset_t oset;
struct sigaction osa, nsa;
- nsa.sa_handler = el_sig_handler;
+ nsa.sa_handler = sig_handler;
nsa.sa_flags = 0;
sigemptyset(&nsa.sa_mask);
@@ -169,7 +169,7 @@ sig_set(EditLine *el)
for (i = 0; sighdl[i] != -1; i++) {
/* This could happen if we get interrupted */
if (sigaction(sighdl[i], &nsa, &osa) != -1 &&
- osa.sa_handler != el_sig_handler)
+ osa.sa_handler != sig_handler)
el->el_signal->sig_action[i] = osa;
}
sel = el;
=== modified file 'cmd-line-utils/libedit/sys.h'
--- a/cmd-line-utils/libedit/sys.h 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/sys.h 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys.h,v 1.14 2011/07/28 00:45:30 christos Exp $ */
+/* $NetBSD: sys.h,v 1.15 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -75,16 +75,6 @@
# define __arraycount(a) (sizeof(a) / sizeof(*(a)))
#endif
-#ifndef _PTR_T
-# define _PTR_T
-typedef void *ptr_t;
-#endif
-
-#ifndef _IOCTL_T
-# define _IOCTL_T
-typedef void *ioctl_t;
-#endif
-
#include <stdio.h>
#ifndef HAVE_STRLCAT
@@ -174,8 +164,8 @@ extern void perror(const char *);
# define strerror(e) sys_errlist[e]
# endif
# ifdef SABER
-extern ptr_t memcpy(ptr_t, const ptr_t, size_t);
-extern ptr_t memset(ptr_t, int, size_t);
+extern void * memcpy(void *, const void *, size_t);
+extern void * memset(void *, int, size_t);
# endif
extern char *fgetline(FILE *, int *);
#endif
=== modified file 'cmd-line-utils/libedit/terminal.c'
--- a/cmd-line-utils/libedit/terminal.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/terminal.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: terminal.c,v 1.3 2011/07/28 03:52:19 christos Exp $ */
+/* $NetBSD: terminal.c,v 1.4 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -340,25 +340,31 @@ protected int
terminal_init(EditLine *el)
{
- el->el_terminal.t_buf = (char *) el_malloc(TC_BUFSIZE);
+ el->el_terminal.t_buf = el_malloc(TC_BUFSIZE *
+ sizeof(*el->el_terminal.t_buf));
if (el->el_terminal.t_buf == NULL)
return (-1);
- el->el_terminal.t_cap = (char *) el_malloc(TC_BUFSIZE);
+ el->el_terminal.t_cap = el_malloc(TC_BUFSIZE *
+ sizeof(*el->el_terminal.t_cap));
if (el->el_terminal.t_cap == NULL)
return (-1);
- el->el_terminal.t_fkey = (funckey_t *) el_malloc(A_K_NKEYS *
- sizeof(funckey_t));
+ el->el_terminal.t_fkey = el_malloc(A_K_NKEYS *
+ sizeof(*el->el_terminal.t_fkey));
if (el->el_terminal.t_fkey == NULL)
return (-1);
el->el_terminal.t_loc = 0;
- el->el_terminal.t_str = (char **) el_malloc(T_str * sizeof(char *));
+ el->el_terminal.t_str = el_malloc(T_str *
+ sizeof(*el->el_terminal.t_str));
if (el->el_terminal.t_str == NULL)
return (-1);
- (void) memset(el->el_terminal.t_str, 0, T_str * sizeof(char *));
- el->el_terminal.t_val = (int *) el_malloc(T_val * sizeof(int));
+ (void) memset(el->el_terminal.t_str, 0, T_str *
+ sizeof(*el->el_terminal.t_str));
+ el->el_terminal.t_val = el_malloc(T_val *
+ sizeof(*el->el_terminal.t_val));
if (el->el_terminal.t_val == NULL)
return (-1);
- (void) memset(el->el_terminal.t_val, 0, T_val * sizeof(int));
+ (void) memset(el->el_terminal.t_val, 0, T_val *
+ sizeof(*el->el_terminal.t_val));
(void) terminal_set(el, NULL);
terminal_init_arrow(el);
return (0);
@@ -371,16 +377,16 @@ protected void
terminal_end(EditLine *el)
{
- el_free((ptr_t) el->el_terminal.t_buf);
+ el_free(el->el_terminal.t_buf);
el->el_terminal.t_buf = NULL;
- el_free((ptr_t) el->el_terminal.t_cap);
+ el_free(el->el_terminal.t_cap);
el->el_terminal.t_cap = NULL;
el->el_terminal.t_loc = 0;
- el_free((ptr_t) el->el_terminal.t_str);
+ el_free(el->el_terminal.t_str);
el->el_terminal.t_str = NULL;
- el_free((ptr_t) el->el_terminal.t_val);
+ el_free(el->el_terminal.t_val);
el->el_terminal.t_val = NULL;
- el_free((ptr_t) el->el_terminal.t_fkey);
+ el_free(el->el_terminal.t_fkey);
el->el_terminal.t_fkey = NULL;
terminal_free_display(el);
}
@@ -487,8 +493,8 @@ terminal_alloc_display(EditLine *el)
b[i] = el_malloc(sizeof(**b) * (c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
- el_free((ptr_t) b[i]);
- el_free((ptr_t) b);
+ el_free(b[i]);
+ el_free(b);
return (-1);
}
}
@@ -502,8 +508,8 @@ terminal_alloc_display(EditLine *el)
b[i] = el_malloc(sizeof(**b) * (c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
- el_free((ptr_t) b[i]);
- el_free((ptr_t) b);
+ el_free(b[i]);
+ el_free(b);
return (-1);
}
}
@@ -526,15 +532,15 @@ terminal_free_display(EditLine *el)
el->el_display = NULL;
if (b != NULL) {
for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) *bufp);
- el_free((ptr_t) b);
+ el_free(*bufp);
+ el_free(b);
}
b = el->el_vdisplay;
el->el_vdisplay = NULL;
if (b != NULL) {
for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) *bufp);
- el_free((ptr_t) b);
+ el_free(*bufp);
+ el_free(b);
}
}
@@ -1030,7 +1036,7 @@ terminal_get_size(EditLine *el, int *lin
#ifdef TIOCGWINSZ
{
struct winsize ws;
- if (ioctl(el->el_infd, TIOCGWINSZ, (ioctl_t) & ws) != -1) {
+ if (ioctl(el->el_infd, TIOCGWINSZ, &ws) != -1) {
if (ws.ws_col)
*cols = ws.ws_col;
if (ws.ws_row)
@@ -1041,7 +1047,7 @@ terminal_get_size(EditLine *el, int *lin
#ifdef TIOCGSIZE
{
struct ttysize ts;
- if (ioctl(el->el_infd, TIOCGSIZE, (ioctl_t) & ts) != -1) {
+ if (ioctl(el->el_infd, TIOCGSIZE, &ts) != -1) {
if (ts.ts_cols)
*cols = ts.ts_cols;
if (ts.ts_lines)
=== modified file 'cmd-line-utils/libedit/tokenizer.c'
--- a/cmd-line-utils/libedit/tokenizer.c 2011-05-13 08:32:47 +0000
+++ b/cmd-line-utils/libedit/tokenizer.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tokenizer.c,v 1.18 2010/01/03 18:27:10 christos Exp $ */
+/* $NetBSD: tokenizer.c,v 1.19 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -105,29 +105,29 @@ FUN(tok,finish)(TYPE(Tokenizer) *tok)
public TYPE(Tokenizer) *
FUN(tok,init)(const Char *ifs)
{
- TYPE(Tokenizer) *tok = tok_malloc(sizeof(TYPE(Tokenizer)));
+ TYPE(Tokenizer) *tok = tok_malloc(sizeof(*tok));
if (tok == NULL)
return NULL;
tok->ifs = tok_strdup(ifs ? ifs : IFS);
if (tok->ifs == NULL) {
- tok_free((ptr_t)tok);
+ tok_free(tok);
return NULL;
}
tok->argc = 0;
tok->amax = AINCR;
tok->argv = tok_malloc(sizeof(*tok->argv) * tok->amax);
if (tok->argv == NULL) {
- tok_free((ptr_t)tok->ifs);
- tok_free((ptr_t)tok);
+ tok_free(tok->ifs);
+ tok_free(tok);
return NULL;
}
tok->argv[0] = NULL;
tok->wspace = tok_malloc(WINCR * sizeof(*tok->wspace));
if (tok->wspace == NULL) {
- tok_free((ptr_t)tok->argv);
- tok_free((ptr_t)tok->ifs);
- tok_free((ptr_t)tok);
+ tok_free(tok->argv);
+ tok_free(tok->ifs);
+ tok_free(tok);
return NULL;
}
tok->wmax = tok->wspace + WINCR;
@@ -162,10 +162,10 @@ public void
FUN(tok,end)(TYPE(Tokenizer) *tok)
{
- tok_free((ptr_t) tok->ifs);
- tok_free((ptr_t) tok->wspace);
- tok_free((ptr_t) tok->argv);
- tok_free((ptr_t) tok);
+ tok_free(tok->ifs);
+ tok_free(tok->wspace);
+ tok_free(tok->argv);
+ tok_free(tok);
}
=== modified file 'cmd-line-utils/libedit/vi.c'
--- a/cmd-line-utils/libedit/vi.c 2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/vi.c 2011-07-29 10:02:07 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vi.c,v 1.35 2011/07/28 00:45:14 christos Exp $ */
+/* $NetBSD: vi.c,v 1.36 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -1020,7 +1020,7 @@ vi_histedit(EditLine *el, Int c __attrib
return CC_ERROR;
len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
#define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
- cp = el_malloc(TMP_BUFSIZ);
+ cp = el_malloc(TMP_BUFSIZ * sizeof(*cp));
if (cp == NULL) {
unlink(tempfile);
close(fd);
@@ -1028,7 +1028,7 @@ vi_histedit(EditLine *el, Int c __attrib
}
line = el_malloc(len * sizeof(*line));
if (line == NULL) {
- el_free((ptr_t)cp);
+ el_free(cp);
return CC_ERROR;
}
Strncpy(line, el->el_line.buffer, len);
No bundle (reason: useless for push emails).| Thread |
|---|
| • bzr push into mysql-trunk branch (nirbhay.choubey:3240 to 3241) WL#5945 | Nirbhay Choubey | 3 Aug |