Removed xalloc type functions from library
These xalloc functions are a private function for the library. If using programs need them, then they should make their own error reporting or use a common file.
This commit is contained in:
parent
562b4a039f
commit
2865ded64e
@ -71,11 +71,6 @@ global:
|
||||
vm_pswpin;
|
||||
vm_pswpout;
|
||||
vminfo;
|
||||
xalloc_err_handler;
|
||||
xcalloc;
|
||||
xmalloc;
|
||||
xrealloc;
|
||||
xstrdup;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
|
@ -237,7 +237,7 @@ static void lists_and_needs(void){
|
||||
format_node *p_end = &pfn;
|
||||
format_node *t_end = &tfn;
|
||||
while(walk){
|
||||
format_node *new = xmalloc(sizeof(format_node));
|
||||
format_node *new = malloc(sizeof(format_node));
|
||||
memcpy(new,walk,sizeof(format_node));
|
||||
p_end->next = walk;
|
||||
t_end->next = new;
|
||||
@ -381,7 +381,7 @@ static void prep_forest_sort(void){
|
||||
if(!sort_list) { /* assume start time order */
|
||||
incoming = search_format_array("start_time");
|
||||
if(!incoming) { fprintf(stderr, "Could not find start_time!\n"); exit(1); }
|
||||
tmp_list = xmalloc(sizeof(sort_node));
|
||||
tmp_list = malloc(sizeof(sort_node));
|
||||
tmp_list->reverse = 0;
|
||||
tmp_list->typecode = '?'; /* what was this for? */
|
||||
tmp_list->sr = incoming->sr;
|
||||
@ -392,7 +392,7 @@ static void prep_forest_sort(void){
|
||||
/* this is required for the forest option */
|
||||
incoming = search_format_array("ppid");
|
||||
if(!incoming) { fprintf(stderr, "Could not find ppid!\n"); exit(1); }
|
||||
tmp_list = xmalloc(sizeof(sort_node));
|
||||
tmp_list = malloc(sizeof(sort_node));
|
||||
tmp_list->reverse = 0;
|
||||
tmp_list->typecode = '?'; /* what was this for? */
|
||||
tmp_list->sr = incoming->sr;
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <sys/sysmacros.h>
|
||||
#include "../proc/alloc.h"
|
||||
#include "../proc/wchan.h"
|
||||
#include "../proc/version.h"
|
||||
#include "../proc/sysinfo.h"
|
||||
@ -234,7 +233,10 @@ static const char *set_personality(void){
|
||||
if(sl > 15) return "Environment specified an unknown personality.";
|
||||
strncpy(buf, s, sl);
|
||||
buf[sl] = '\0';
|
||||
saved_personality_text = xstrdup(buf);
|
||||
if ((saved_personality_text = strdup(buf))==NULL) {
|
||||
fprintf(stderr, "Cannot strdup() personality text.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
found = bsearch(&findme, personality_table, personality_table_count,
|
||||
sizeof(personality_table_struct), compare_personality_table_structs
|
||||
|
26
ps/parser.c
26
ps/parser.c
@ -174,10 +174,10 @@ static const char *parse_list(const char *arg, const char *(*parse_fn)(char *, s
|
||||
int need_item;
|
||||
const char *err; /* error code that could or did happen */
|
||||
/*** prepare to operate ***/
|
||||
node = xmalloc(sizeof(selection_node));
|
||||
node->u = xmalloc(strlen(arg)*sizeof(sel_union)); /* waste is insignificant */
|
||||
node = malloc(sizeof(selection_node));
|
||||
node->u = malloc(strlen(arg)*sizeof(sel_union)); /* waste is insignificant */
|
||||
node->n = 0;
|
||||
buf = xstrdup(arg);
|
||||
buf = strdup(arg);
|
||||
/*** sanity check and count items ***/
|
||||
need_item = 1; /* true */
|
||||
items = 0;
|
||||
@ -576,8 +576,8 @@ static const char *parse_bsd_option(void){
|
||||
/* put our tty on a tiny list */
|
||||
{
|
||||
selection_node *node;
|
||||
node = xmalloc(sizeof(selection_node));
|
||||
node->u = xmalloc(sizeof(sel_union));
|
||||
node = malloc(sizeof(selection_node));
|
||||
node->u = malloc(sizeof(sel_union));
|
||||
node->u[0].tty = cached_tty;
|
||||
node->typecode = SEL_TTY;
|
||||
node->n = 1;
|
||||
@ -705,8 +705,8 @@ static const char *parse_bsd_option(void){
|
||||
if(!arg){
|
||||
/* Wow, obsolete BSD syntax. Put our tty on a tiny list. */
|
||||
selection_node *node;
|
||||
node = xmalloc(sizeof(selection_node));
|
||||
node->u = xmalloc(sizeof(sel_union));
|
||||
node = malloc(sizeof(selection_node));
|
||||
node->u = malloc(sizeof(sel_union));
|
||||
node->u[0].tty = cached_tty;
|
||||
node->typecode = SEL_TTY;
|
||||
node->n = 1;
|
||||
@ -1018,16 +1018,16 @@ static const char *parse_trailing_pids(void){
|
||||
argp = ps_argv + thisarg;
|
||||
thisarg = ps_argc - 1; /* we must be at the end now */
|
||||
|
||||
pidnode = xmalloc(sizeof(selection_node));
|
||||
pidnode->u = xmalloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
pidnode = malloc(sizeof(selection_node));
|
||||
pidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
pidnode->n = 0;
|
||||
|
||||
grpnode = xmalloc(sizeof(selection_node));
|
||||
grpnode->u = xmalloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
grpnode = malloc(sizeof(selection_node));
|
||||
grpnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
grpnode->n = 0;
|
||||
|
||||
sidnode = xmalloc(sizeof(selection_node));
|
||||
sidnode->u = xmalloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
sidnode = malloc(sizeof(selection_node));
|
||||
sidnode->u = malloc(i*sizeof(sel_union)); /* waste is insignificant */
|
||||
sidnode->n = 0;
|
||||
|
||||
while(i--){
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
|
||||
#include "../proc/alloc.h"
|
||||
#include "../proc/readproc.h"
|
||||
#include "../proc/sysinfo.h"
|
||||
#include "common.h"
|
||||
@ -39,7 +38,7 @@ static format_node *do_one_spec(const char *spec, const char *override){
|
||||
if(fs){
|
||||
int w1, w2;
|
||||
format_node *thisnode;
|
||||
thisnode = xmalloc(sizeof(format_node));
|
||||
thisnode = malloc(sizeof(format_node));
|
||||
if(fs->flags & CF_PIDMAX){
|
||||
w1 = (int)get_pid_digits();
|
||||
w2 = strlen(fs->head);
|
||||
@ -50,10 +49,10 @@ static format_node *do_one_spec(const char *spec, const char *override){
|
||||
if(override){
|
||||
w2 = strlen(override);
|
||||
thisnode->width = (w1>w2)?w1:w2;
|
||||
thisnode->name = xstrdup(override);
|
||||
thisnode->name = strdup(override);
|
||||
}else{
|
||||
thisnode->width = w1;
|
||||
thisnode->name = xstrdup(fs->head);
|
||||
thisnode->name = strdup(fs->head);
|
||||
}
|
||||
thisnode->pr = fs->pr;
|
||||
thisnode->need = fs->need;
|
||||
@ -143,7 +142,7 @@ static const char *aix_format_parse(sf_node *sfn){
|
||||
}
|
||||
|
||||
/*** sanity check passed ***/
|
||||
buf = xstrdup(sfn->sf);
|
||||
buf = strdup(sfn->sf);
|
||||
walk = sfn->sf;
|
||||
|
||||
while(items--){
|
||||
@ -176,9 +175,9 @@ double_percent:
|
||||
}
|
||||
buf[len] = '\0';
|
||||
walk += len;
|
||||
fnode = xmalloc(sizeof(format_node));
|
||||
fnode = malloc(sizeof(format_node));
|
||||
fnode->width = len;
|
||||
fnode->name = xstrdup(buf);
|
||||
fnode->name = strdup(buf);
|
||||
fnode->pr = NULL; /* checked for */
|
||||
fnode->need = 0;
|
||||
fnode->vendor = AIX;
|
||||
@ -212,7 +211,7 @@ static const char *format_parse(sf_node *sfn){
|
||||
static char errbuf[80]; /* for variable-text error message */
|
||||
|
||||
/*** prepare to operate ***/
|
||||
buf = xstrdup(sfn->sf);
|
||||
buf = strdup(sfn->sf);
|
||||
|
||||
/*** sanity check and count items ***/
|
||||
need_item = 1; /* true */
|
||||
@ -327,7 +326,7 @@ static sort_node *do_one_sort_spec(const char *spec){
|
||||
fs = search_format_array(spec);
|
||||
if(fs){
|
||||
sort_node *thisnode;
|
||||
thisnode = xmalloc(sizeof(sort_node));
|
||||
thisnode = malloc(sizeof(sort_node));
|
||||
thisnode->sr = fs->sr;
|
||||
thisnode->need = fs->need;
|
||||
thisnode->reverse = reverse;
|
||||
@ -351,7 +350,7 @@ static const char *long_sort_parse(sf_node *sfn){
|
||||
int need_item;
|
||||
|
||||
/*** prepare to operate ***/
|
||||
buf = xstrdup(sfn->sf);
|
||||
buf = strdup(sfn->sf);
|
||||
|
||||
/*** sanity check and count items ***/
|
||||
need_item = 1; /* true */
|
||||
@ -555,8 +554,8 @@ int defer_sf_option(const char *arg, int source){
|
||||
const format_struct *fs;
|
||||
int need_item = 1;
|
||||
|
||||
sfn = xmalloc(sizeof(sf_node));
|
||||
sfn->sf = xstrdup(arg);
|
||||
sfn = malloc(sizeof(sf_node));
|
||||
sfn->sf = strdup(arg);
|
||||
sfn->sf_code = source;
|
||||
sfn->s_cooked = NULL;
|
||||
sfn->f_cooked = NULL;
|
||||
@ -679,9 +678,9 @@ static const char *generate_sysv_list(void){
|
||||
if( (format_flags & FF_Ul) && !(format_modifiers & FM_y) ){
|
||||
if(personality & PER_IRIX_l){ /* add "rss" then ':' here */
|
||||
PUSH("sgi_rss");
|
||||
fn = xmalloc(sizeof(format_node));
|
||||
fn = malloc(sizeof(format_node));
|
||||
fn->width = 1;
|
||||
fn->name = xstrdup(":");
|
||||
fn->name = strdup(":");
|
||||
fn->pr = NULL; /* checked for */
|
||||
fn->need = 0;
|
||||
fn->vendor = AIX; /* yes, for SGI weirdness */
|
||||
|
17
top.c
17
top.c
@ -39,7 +39,6 @@
|
||||
#include <unistd.h>
|
||||
#include <values.h>
|
||||
|
||||
#include "proc/alloc.h"
|
||||
#include "proc/devname.h"
|
||||
#include "proc/procps.h"
|
||||
#include "proc/readproc.h"
|
||||
@ -1319,7 +1318,7 @@ static void adj_geometry (void) {
|
||||
// we'll only grow our Pseudo_screen, never shrink it
|
||||
if (pseudo_max < Pseudo_size) {
|
||||
pseudo_max = Pseudo_size;
|
||||
Pseudo_screen = xrealloc(Pseudo_screen, pseudo_max);
|
||||
Pseudo_screen = realloc(Pseudo_screen, pseudo_max);
|
||||
}
|
||||
PSU_CLREOS(0);
|
||||
if (Frames_resize) putp(Cap_clr_scr);
|
||||
@ -1769,7 +1768,8 @@ static CPU_t *cpus_refresh (CPU_t *cpus) {
|
||||
/* note: we allocate one more CPU_t than Cpu_tot so that the last slot
|
||||
can hold tics representing the /proc/stat cpu summary (the first
|
||||
line read) -- that slot supports our View_CPUSUM toggle */
|
||||
cpus = xcalloc((1 + Cpu_tot) * sizeof(CPU_t));
|
||||
if ((cpus = calloc((1 + Cpu_tot),sizeof(CPU_t)))==NULL)
|
||||
error_exit(fmtmk("failed to allocate memory for CPU_t"));
|
||||
}
|
||||
rewind(fp);
|
||||
fflush(fp);
|
||||
@ -1920,8 +1920,8 @@ static void prochlp (proc_t *this) {
|
||||
|
||||
if (Frame_maxtask+1 >= HHist_siz) {
|
||||
HHist_siz = HHist_siz * 5 / 4 + 100;
|
||||
PHist_sav = xrealloc(PHist_sav, sizeof(HST_t) * HHist_siz);
|
||||
PHist_new = xrealloc(PHist_new, sizeof(HST_t) * HHist_siz);
|
||||
PHist_sav = realloc(PHist_sav, sizeof(HST_t) * HHist_siz);
|
||||
PHist_new = realloc(PHist_new, sizeof(HST_t) * HHist_siz);
|
||||
}
|
||||
|
||||
/* calculate time in this process; the sum of user time (utime) and
|
||||
@ -1971,7 +1971,7 @@ static void procs_refresh (void) {
|
||||
for (;;) {
|
||||
if (n_used == n_alloc) {
|
||||
n_alloc = 10 + ((n_alloc * 5) / 4); // grow by over 25%
|
||||
private_ppt = xrealloc(private_ppt, sizeof(proc_t*) * n_alloc);
|
||||
private_ppt = realloc(private_ppt, sizeof(proc_t*) * n_alloc);
|
||||
// ensure NULL pointers for the additional memory just acquired
|
||||
memset(private_ppt + n_used, 0, sizeof(proc_t*) * (n_alloc - n_used));
|
||||
}
|
||||
@ -1990,7 +1990,7 @@ static void procs_refresh (void) {
|
||||
else {
|
||||
n_saved = n_alloc;
|
||||
for (i = 0; i < GROUPSMAX; i++) {
|
||||
Winstk[i].ppt = xrealloc(Winstk[i].ppt, sizeof(proc_t*) * n_alloc);
|
||||
Winstk[i].ppt = realloc(Winstk[i].ppt, sizeof(proc_t*) * n_alloc);
|
||||
memcpy(Winstk[i].ppt, private_ppt, sizeof(proc_t*) * n_used);
|
||||
}
|
||||
}
|
||||
@ -2038,7 +2038,6 @@ static void before (char *me) {
|
||||
// setup our program name and library error message handler -- big!
|
||||
Myname = strrchr(me, '/');
|
||||
if (Myname) ++Myname; else Myname = me;
|
||||
xalloc_err_handler = library_err;
|
||||
|
||||
// establish cpu particulars -- even bigger!
|
||||
#ifdef PRETEND4CPUS
|
||||
@ -3153,7 +3152,7 @@ static void forest_create (WIN_t *q) {
|
||||
qsort(Seed_ppt, Frame_maxtask, sizeof(proc_t*), Fieldstab[P_PPD].sort);
|
||||
if (hwmsav < Frame_maxtask) { // grow, but never shrink
|
||||
hwmsav = Frame_maxtask;
|
||||
Tree_ppt = xrealloc(Tree_ppt, sizeof(proc_t*) * hwmsav);
|
||||
Tree_ppt = realloc(Tree_ppt, sizeof(proc_t*) * hwmsav);
|
||||
}
|
||||
while (0 == Seed_ppt[i]->ppid) // identify trees (expect 2)
|
||||
forest_add(i++, 1); // add parent plus children
|
||||
|
Loading…
Reference in New Issue
Block a user