Add xzalloc function to reduce size.

This commit is contained in:
Roy Marples 2008-01-30 14:34:55 +00:00
parent b49f779779
commit 61e36be694
2 changed files with 19 additions and 21 deletions

View File

@ -211,8 +211,7 @@ pid_t *rc_find_pids (const char *exec, const char *cmd,
}
#ifdef _KVM_GETPROC2
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2),
&processes);
kp = kvm_getproc2 (kd, KERN_PROC_ALL, 0, sizeof(*kp), &processes);
#else
kp = kvm_getprocs (kd, KERN_PROC_PROC, 0, &processes);
#endif

View File

@ -43,6 +43,13 @@ struct lhead
char **list;
};
static void *xzalloc (size_t size)
{
void *value = xmalloc (size);
memset (value, 0, size);
return (value);
}
static char *get_shell_value (char *string)
{
char *p = string;
@ -156,15 +163,14 @@ rc_depinfo_t *rc_deptree_load (void)
if (! deptree)
{
deptree = xmalloc (sizeof (rc_depinfo_t));
deptree = xzalloc (sizeof (rc_depinfo_t));
depinfo = deptree;
}
else
{
depinfo->next = xmalloc (sizeof (rc_depinfo_t));
depinfo->next = xzalloc (sizeof (rc_depinfo_t));
depinfo = depinfo->next;
}
memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = xstrdup (e);
deptype = NULL;
goto next;
@ -181,16 +187,14 @@ rc_depinfo_t *rc_deptree_load (void)
if (! deptype)
{
depinfo->depends = xmalloc (sizeof (rc_deptype_t));
depinfo->depends = xzalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends;
memset (deptype, 0, sizeof (rc_deptype_t));
}
else
if (strcmp (deptype->type, type) != 0)
{
deptype->next = xmalloc (sizeof (rc_deptype_t));
deptype->next = xzalloc (sizeof (rc_deptype_t));
deptype = deptype->next;
memset (deptype, 0, sizeof (rc_deptype_t));
}
if (! deptype->type)
@ -750,8 +754,7 @@ bool rc_deptree_update (void)
if (! (fp = popen (GENDEP, "r")))
return (false);
deptree = xmalloc (sizeof (rc_depinfo_t));
memset (deptree, 0, sizeof (rc_depinfo_t));
deptree = xzalloc (sizeof (*deptree));
/* Phase 2 */
while ((line = rc_getline (fp)))
@ -775,10 +778,9 @@ bool rc_deptree_update (void)
depinfo = last_depinfo;
else
{
last_depinfo->next = xmalloc (sizeof (rc_depinfo_t));
last_depinfo->next = xzalloc (sizeof (rc_depinfo_t));
depinfo = last_depinfo->next;
}
memset (depinfo, 0, sizeof (rc_depinfo_t));
depinfo->service = xstrdup (service);
}
@ -800,15 +802,14 @@ bool rc_deptree_update (void)
{
if (! last_deptype)
{
depinfo->depends = xmalloc (sizeof (rc_deptype_t));
depinfo->depends = xzalloc (sizeof (rc_deptype_t));
deptype = depinfo->depends;
}
else
{
last_deptype->next = xmalloc (sizeof (rc_deptype_t));
last_deptype->next = xzalloc (sizeof (rc_deptype_t));
deptype = last_deptype->next;
}
memset (deptype, 0, sizeof (rc_deptype_t));
deptype->type = xstrdup (type);
}
}
@ -876,9 +877,8 @@ next:
}
if (! di)
{
last_depinfo->next = xmalloc (sizeof (rc_depinfo_t));
last_depinfo->next = xzalloc (sizeof (rc_depinfo_t));
di = last_depinfo->next;
memset (di, 0, sizeof (rc_depinfo_t));
di->service = xstrdup (service);
}
}
@ -919,15 +919,14 @@ next:
{
if (! last_deptype)
{
di->depends = xmalloc (sizeof (rc_deptype_t));
di->depends = xzalloc (sizeof (rc_deptype_t));
dt = di->depends;
}
else
{
last_deptype->next = xmalloc (sizeof (rc_deptype_t));
last_deptype->next = xzalloc (sizeof (rc_deptype_t));
dt = last_deptype->next;
}
memset (dt, 0, sizeof (rc_deptype_t));
dt->type = xstrdup (deppairs[i].addto);
}