die();
}
+void die_out_of_memory(void)
+{
+ static bool recursed = 0;
+ if (recursed)
+ exit(1);
+ recursed = 1;
+ error_msg_and_die("Out of memory");
+}
+
#ifdef SVR4
#ifdef MIPS
void
swap_uid();
fp = fdopen(fds[1], "w");
if (!fp)
- error_msg_and_die("Out of memory");
+ die_out_of_memory();
return fp;
}
/* Allocate the initial tcbtab. */
tcbtabsize = argc; /* Surely enough for all -p args. */
tcbtab = calloc(tcbtabsize, sizeof(tcbtab[0]));
- if (tcbtab == NULL)
- error_msg_and_die("Out of memory");
+ if (!tcbtab)
+ die_out_of_memory();
tcp = calloc(tcbtabsize, sizeof(*tcp));
- if (tcp == NULL)
- error_msg_and_die("Out of memory");
+ if (!tcp)
+ die_out_of_memory();
for (c = 0; c < tcbtabsize; c++)
tcbtab[c] = tcp++;
username = strdup(optarg);
break;
case 'E':
- if (putenv(optarg) < 0) {
- error_msg_and_die("Out of memory");
- }
+ if (putenv(optarg) < 0)
+ die_out_of_memory();
break;
default:
usage(stderr, 1);
acolumn_spaces = malloc(acolumn + 1);
if (!acolumn_spaces)
- error_msg_and_die("Out of memory");
+ die_out_of_memory();
memset(acolumn_spaces, ' ', acolumn);
acolumn_spaces[acolumn] = '\0';
int i = tcbtabsize;
struct tcb *newtcbs = calloc(tcbtabsize, sizeof(newtcbs[0]));
struct tcb **newtab = realloc(tcbtab, tcbtabsize * 2 * sizeof(tcbtab[0]));
- if (newtab == NULL || newtcbs == NULL)
- error_msg_and_die("Out of memory");
+ if (!newtab || !newtcbs)
+ die_out_of_memory();
tcbtabsize *= 2;
tcbtab = newtab;
while (i < tcbtabsize)
free(pollv);
pollv = malloc(nprocs * sizeof(pollv[0]));
- if (pollv == NULL) {
- error_msg_and_die("Out of memory");
- }
+ if (!pollv)
+ die_out_of_memory();
for (i = j = 0; i < tcbtabsize; i++) {
struct tcb *tcp = tcbtab[i];
curcol += n;
}
va_end(args);
- return;
+}
+
+void
+tprints(const char *str)
+{
+ if (outf) {
+ int n = fputs(str, outf);
+ if (n >= 0) {
+ curcol += strlen(str);
+ return;
+ }
+ if (outf != stderr)
+ perror(outfname == NULL
+ ? "<writing to pipe>" : outfname);
+ }
}
void
tabto(void)
{
if (curcol < acolumn)
- tprintf(acolumn_spaces + curcol);
+ tprints(acolumn_spaces + curcol);
}
void