segfaulting or handling errors the same way themselves.
headerL_t *list;
off_t initialOffset;
- list = (headerL_t *) malloc(sizeof(headerL_t));
+ list = (headerL_t *) xmalloc(sizeof(headerL_t));
initialOffset=lseek(srcFd, 0, SEEK_CUR);
if (checkArMagic(srcFd)==TRUE)
ar=TRUE;
if (tar==TRUE) {
while(readTarHeader(srcFd, list)==TRUE) {
off_t tarOffset;
- list->next = (headerL_t *) malloc(sizeof(headerL_t));
+ list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
if (readArEntry(srcFd, list) == FALSE)
return(head);
}
- list->next = (headerL_t *) malloc(sizeof(headerL_t));
+ list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
/* recursive check for sub-archives */
return (FALSE);
}
optind++;
- entry = (headerL_t *) malloc(sizeof(headerL_t));
- header = (headerL_t *) malloc(sizeof(headerL_t));
- extractList = (headerL_t *) malloc(sizeof(headerL_t));
+ entry = (headerL_t *) xmalloc(sizeof(headerL_t));
+ header = (headerL_t *) xmalloc(sizeof(headerL_t));
+ extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
header = getHeaders(srcFd, header, funct);
/* find files to extract or display */
/* only handle specified files */
while(optind < argc) {
if ( (entry = findEntry(header, argv[optind])) != NULL) {
- entry->next = (headerL_t *) malloc(sizeof(headerL_t));
+ entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*entry->next = *extractList;
*extractList = *entry;
}
headerL_t *list;
off_t initialOffset;
- list = (headerL_t *) malloc(sizeof(headerL_t));
+ list = (headerL_t *) xmalloc(sizeof(headerL_t));
initialOffset=lseek(srcFd, 0, SEEK_CUR);
if (checkArMagic(srcFd)==TRUE)
ar=TRUE;
if (tar==TRUE) {
while(readTarHeader(srcFd, list)==TRUE) {
off_t tarOffset;
- list->next = (headerL_t *) malloc(sizeof(headerL_t));
+ list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
if (readArEntry(srcFd, list) == FALSE)
return(head);
}
- list->next = (headerL_t *) malloc(sizeof(headerL_t));
+ list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*list->next = *head;
*head = *list;
/* recursive check for sub-archives */
return (FALSE);
}
optind++;
- entry = (headerL_t *) malloc(sizeof(headerL_t));
- header = (headerL_t *) malloc(sizeof(headerL_t));
- extractList = (headerL_t *) malloc(sizeof(headerL_t));
+ entry = (headerL_t *) xmalloc(sizeof(headerL_t));
+ header = (headerL_t *) xmalloc(sizeof(headerL_t));
+ extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
header = getHeaders(srcFd, header, funct);
/* find files to extract or display */
/* only handle specified files */
while(optind < argc) {
if ( (entry = findEntry(header, argv[optind])) != NULL) {
- entry->next = (headerL_t *) malloc(sizeof(headerL_t));
+ entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
*entry->next = *extractList;
*extractList = *entry;
}
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
{
char *dirName;
- char **matches = (char **) NULL;
+ char **matches;
DIR *dir;
struct dirent *next;
- matches = malloc( sizeof(char*)*50);
+ matches = xmalloc( sizeof(char*)*50);
/* Stick a wildcard onto the command, for later use */
strcat( command, "*");
/* See if this matches */
if (check_wildcard_match(next->d_name, command) == TRUE) {
/* Cool, found a match. Add it to the list */
- matches[*num_matches] = malloc(strlen(next->d_name)+1);
+ matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
strcpy( matches[*num_matches], next->d_name);
++*num_matches;
//matches = realloc( matches, sizeof(char*)*(*num_matches));
/* Make a local copy of the string -- up
* to the position of the cursor */
- matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
+ matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
strncpy(matchBuf, command, cursor);
tmp=matchBuf;
if (!h) {
/* No previous history -- this memory is never freed */
- h = his_front = malloc(sizeof(struct history));
- h->n = malloc(sizeof(struct history));
+ h = his_front = xmalloc(sizeof(struct history));
+ h->n = xmalloc(sizeof(struct history));
h->p = NULL;
h->s = strdup(command);
history_counter++;
} else {
/* Add a new history command -- this memory is never freed */
- h->n = malloc(sizeof(struct history));
+ h->n = xmalloc(sizeof(struct history));
h->n->p = h;
h->n->n = NULL;
u_short unicode;
maxct = tailsz; /* more than enough */
- up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
+ up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
- if (!up) {
- errorMsg("Out of memory?\n");
- exit(1);
- }
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
exit(FALSE);
}
- ibuff = (u_short *) malloc(ibuffsz);
- if (!ibuff) {
- errorMsg("Out of memory.\n");
- exit(FALSE);
- }
+ ibuff = (u_short *) xmalloc(ibuffsz);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
if (linkIntoDirFlag == TRUE) {
char *baseName = get_last_path_component(*argv);
- linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
+ linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
strcpy(linkName, dirName);
if(dirName[strlen(dirName)-1] != '/')
strcat(linkName, "/");
static Line *line_alloc()
{
Line *self;
- self = malloc(1 * sizeof(Line));
+ self = xmalloc(1 * sizeof(Line));
return self;
}
if ((cstring = get_line_from_file(src))) {
self = line_alloc();
- if (self == NULL) {
- return NULL;
- }
self->data = cstring;
self->next = NULL;
return self;
Line *line;
/* mallocate array of Line*s */
- self->sorted = (Line **) malloc(self->len * sizeof(Line *));
- if (self->sorted == NULL) {
- return NULL;
- }
+ self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
/* fill array w/ List's contents */
i = 0;
return(0);
}
-/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */
+/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */
ssize_t f_size=0;
bs=BUFSIZ;
- line=malloc(bs);
+ line=xmalloc(bs);
while(1) {
bytes_read=read(fd,line,bs);
if(bytes_read<=0)
break;
- buffer=realloc(buffer,f_size+bytes_read);
+ buffer=xrealloc(buffer,f_size+bytes_read);
memcpy(&buffer[f_size],line,bytes_read);
filelocation=f_size+=bytes_read;
}
void add_file(char *name)
{
++n_files;
- files = realloc(files, n_files);
- files[n_files - 1] = (char *) malloc(strlen(name) + 1);
+ files = xrealloc(files, n_files);
+ files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
strcpy(files[n_files - 1], name);
}
units=-11;
if(units>0)
units--;
- fd=malloc(sizeof(int)*n_files);
+ fd=xmalloc(sizeof(int)*n_files);
if (n_files == 1)
#ifndef BB_FEATURE_SIMPLE_TAIL
if (!verbose)
#endif
show_headers = 0;
- buffer=malloc(BUFSIZ);
+ buffer=xmalloc(BUFSIZ);
for (test = 0; test < n_files; test++) {
if (show_headers)
printf("==> %s <==\n", files[test]);
initialize_group_array ()
{
ngroups = getgroups(0, NULL);
- if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
- fatalError("Out of space\n");
-
+ group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
getgroups(ngroups, group_array);
}
*/
#include <stdio.h>
-#include <stdlib.h> /* for realloc() */
#include <unistd.h> /* for getopt() */
#include <regex.h>
#include <string.h> /* for strdup() */
continue;
}
/* grow the array */
- sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
+ sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
/* zero new element */
memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
/* load command string into new array element, get remainder */
/* if a line ends with '\' it needs the next line appended to it */
while (line[strlen(line)-2] == '\\' &&
(nextline = get_line_from_file(cmdfile)) != NULL) {
- line = realloc(line, strlen(line) + strlen(nextline) + 1);
+ line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
strcat(line, nextline);
free(nextline);
}
if (!path_list)
path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
- path_parsed = malloc (strlen(path_list) + 1);
+ path_parsed = xmalloc (strlen(path_list) + 1);
strcpy (path_parsed, path_list);
/* Replace colons with zeros in path_parsed and count them */
if (linkIntoDirFlag == TRUE) {
char *baseName = get_last_path_component(*argv);
- linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
+ linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
strcpy(linkName, dirName);
if(dirName[strlen(dirName)-1] != '/')
strcat(linkName, "/");
u_short unicode;
maxct = tailsz; /* more than enough */
- up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
+ up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
- if (!up) {
- errorMsg("Out of memory?\n");
- exit(1);
- }
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
exit(FALSE);
}
- ibuff = (u_short *) malloc(ibuffsz);
- if (!ibuff) {
- errorMsg("Out of memory.\n");
- exit(FALSE);
- }
+ ibuff = (u_short *) xmalloc(ibuffsz);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
if (numfilesystems<0)
fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
- fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
+ fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
/* Grab the list of available filesystems */
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
if (numfilesystems<0)
fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
- mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
+ mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
/* Grab the list of mounted filesystems */
if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
- pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+ pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
- pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+ pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
*/
#include <stdio.h>
-#include <stdlib.h> /* for realloc() */
#include <unistd.h> /* for getopt() */
#include <regex.h>
#include <string.h> /* for strdup() */
continue;
}
/* grow the array */
- sed_cmds = realloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
+ sed_cmds = xrealloc(sed_cmds, sizeof(struct sed_cmd) * (++ncmds));
/* zero new element */
memset(&sed_cmds[ncmds-1], 0, sizeof(struct sed_cmd));
/* load command string into new array element, get remainder */
/* if a line ends with '\' it needs the next line appended to it */
while (line[strlen(line)-2] == '\\' &&
(nextline = get_line_from_file(cmdfile)) != NULL) {
- line = realloc(line, strlen(line) + strlen(nextline) + 1);
+ line = xrealloc(line, strlen(line) + strlen(nextline) + 1);
strcat(line, nextline);
free(nextline);
}
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
{
char *dirName;
- char **matches = (char **) NULL;
+ char **matches;
DIR *dir;
struct dirent *next;
- matches = malloc( sizeof(char*)*50);
+ matches = xmalloc( sizeof(char*)*50);
/* Stick a wildcard onto the command, for later use */
strcat( command, "*");
/* See if this matches */
if (check_wildcard_match(next->d_name, command) == TRUE) {
/* Cool, found a match. Add it to the list */
- matches[*num_matches] = malloc(strlen(next->d_name)+1);
+ matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
strcpy( matches[*num_matches], next->d_name);
++*num_matches;
//matches = realloc( matches, sizeof(char*)*(*num_matches));
/* Make a local copy of the string -- up
* to the position of the cursor */
- matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
+ matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
strncpy(matchBuf, command, cursor);
tmp=matchBuf;
if (!h) {
/* No previous history -- this memory is never freed */
- h = his_front = malloc(sizeof(struct history));
- h->n = malloc(sizeof(struct history));
+ h = his_front = xmalloc(sizeof(struct history));
+ h->n = xmalloc(sizeof(struct history));
h->p = NULL;
h->s = strdup(command);
history_counter++;
} else {
/* Add a new history command -- this memory is never freed */
- h->n = malloc(sizeof(struct history));
+ h->n = xmalloc(sizeof(struct history));
h->n->p = h;
h->n->n = NULL;
static Line *line_alloc()
{
Line *self;
- self = malloc(1 * sizeof(Line));
+ self = xmalloc(1 * sizeof(Line));
return self;
}
if ((cstring = get_line_from_file(src))) {
self = line_alloc();
- if (self == NULL) {
- return NULL;
- }
self->data = cstring;
self->next = NULL;
return self;
Line *line;
/* mallocate array of Line*s */
- self->sorted = (Line **) malloc(self->len * sizeof(Line *));
- if (self->sorted == NULL) {
- return NULL;
- }
+ self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
/* fill array w/ List's contents */
i = 0;
return(0);
}
-/* $Id: sort.c,v 1.20 2000/07/16 20:57:15 kraai Exp $ */
+/* $Id: sort.c,v 1.21 2000/09/13 02:46:13 kraai Exp $ */
ssize_t f_size=0;
bs=BUFSIZ;
- line=malloc(bs);
+ line=xmalloc(bs);
while(1) {
bytes_read=read(fd,line,bs);
if(bytes_read<=0)
break;
- buffer=realloc(buffer,f_size+bytes_read);
+ buffer=xrealloc(buffer,f_size+bytes_read);
memcpy(&buffer[f_size],line,bytes_read);
filelocation=f_size+=bytes_read;
}
void add_file(char *name)
{
++n_files;
- files = realloc(files, n_files);
- files[n_files - 1] = (char *) malloc(strlen(name) + 1);
+ files = xrealloc(files, n_files);
+ files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
strcpy(files[n_files - 1], name);
}
units=-11;
if(units>0)
units--;
- fd=malloc(sizeof(int)*n_files);
+ fd=xmalloc(sizeof(int)*n_files);
if (n_files == 1)
#ifndef BB_FEATURE_SIMPLE_TAIL
if (!verbose)
#endif
show_headers = 0;
- buffer=malloc(BUFSIZ);
+ buffer=xmalloc(BUFSIZ);
for (test = 0; test < n_files; test++) {
if (show_headers)
printf("==> %s <==\n", files[test]);
initialize_group_array ()
{
ngroups = getgroups(0, NULL);
- if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
- fatalError("Out of space\n");
-
+ group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
getgroups(ngroups, group_array);
}
numfilesystems = ioctl (fd, DEVMTAB_COUNT_FILESYSTEMS);
if (numfilesystems<0)
fatalError("\nDEVMTAB_COUNT_FILESYSTEMS: %s\n", strerror (errno));
- fslist = (struct k_fstype *) calloc ( numfilesystems, sizeof(struct k_fstype));
+ fslist = (struct k_fstype *) xcalloc ( numfilesystems, sizeof(struct k_fstype));
/* Grab the list of available filesystems */
status = ioctl (fd, DEVMTAB_GET_FILESYSTEMS, fslist);
numfilesystems = ioctl (fd, DEVMTAB_COUNT_MOUNTS);
if (numfilesystems<0)
fatalError( "\nDEVMTAB_COUNT_MOUNTS: %s\n", strerror (errno));
- mntentlist = (struct k_mntent *) calloc ( numfilesystems, sizeof(struct k_mntent));
+ mntentlist = (struct k_mntent *) xcalloc ( numfilesystems, sizeof(struct k_mntent));
/* Grab the list of mounted filesystems */
if (ioctl (fd, DEVMTAB_GET_MOUNTS, mntentlist)<0)
* some new processes start up while we wait. The kernel will
* just ignore any extras if we give it too many, and will trunc.
* the list if we give it too few. */
- pid_array = (pid_t*) calloc( num_pids+10, sizeof(pid_t));
+ pid_array = (pid_t*) xcalloc( num_pids+10, sizeof(pid_t));
pid_array[0] = num_pids+10;
/* Now grab the pid list */
if ((strstr(info.command_line, pidName) != NULL)
&& (strlen(pidName) == strlen(info.command_line))) {
- pidList=realloc( pidList, sizeof(pid_t) * (j+2));
- if (pidList==NULL)
- fatalError(memory_exhausted);
+ pidList=xrealloc( pidList, sizeof(pid_t) * (j+2));
pidList[j++]=info.pid;
}
}
if ((strstr(p, pidName) != NULL)
&& (strlen(pidName) == strlen(p))) {
- pidList=realloc( pidList, sizeof(pid_t) * (i+2));
- if (pidList==NULL)
- fatalError(memory_exhausted);
+ pidList=xrealloc( pidList, sizeof(pid_t) * (i+2));
pidList[i++]=strtol(next->d_name, NULL, 0);
}
}
break;
/* grow the line buffer as necessary */
if (idx > linebufsz-2)
- linebuf = realloc(linebuf, linebufsz += GROWBY);
+ linebuf = xrealloc(linebuf, linebufsz += GROWBY);
linebuf[idx++] = (char)ch;
if ((char)ch == '\n')
break;
if (!path_list)
path_list = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin";
- path_parsed = malloc (strlen(path_list) + 1);
+ path_parsed = xmalloc (strlen(path_list) + 1);
strcpy (path_parsed, path_list);
/* Replace colons with zeros in path_parsed and count them */