summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorrcyeske <rcyeske>2001-03-02 06:06:23 +0000
committerrcyeske <rcyeske>2001-03-02 06:06:23 +0000
commit46d33884f2f1061ae1a77c26928f97d573e57c6c (patch)
tree39c8a9fe54a29d761a797cc9124f945ded2ecc3c /src/main.c
parent58e95be4eab6d82257214d76414c9eef901c5915 (diff)
downloadratpoison-46d33884f2f1061ae1a77c26928f97d573e57c6c.zip
* ratpoison.h (xmalloc, xrealloc, fatal): Prototype.
* main.c (xmalloc): Move here from sbuf.c. (xrealloc): Likewise. (fatal): Likewise. * number.c (find_empty_cell): Use xrealloc, remove error check. (init_numbers): Likewise. * manage.c (get_window_name): Likewise. * main.c (main): Likewise. * list.c (add_to_window_list): Likewise. (add_to_window_list): Likewise. * events.c (handle_key): Likewise. * input.c (keysym_to_string): Likewise. (get_more_input): Use xrealloc, remove error check. * main.c (read_rc_file): Take a file pointer rather than a filename. (read_startup_files): If ~/.ratpoisonrc is not readable try /etc/ratpoisonrc.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/src/main.c b/src/main.c
index 802d37f..1ccebe8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -74,6 +74,32 @@ static struct option ratpoison_longopts[] = { {"help", no_argument, 0, 'h'},
static char ratpoison_opts[] = "hvrk";
void
+fatal (const char *msg)
+{
+ fprintf (stderr, "ratpoison: %s", msg);
+ abort ();
+}
+
+void *
+xmalloc (size_t size)
+{
+ register void *value = malloc (size);
+ if (value == 0)
+ fatal ("Virtual memory exhausted");
+ return value;
+}
+
+void *
+xrealloc (void *ptr, size_t size)
+{
+ register void *value = realloc (ptr, size);
+ if (value == 0)
+ fatal ("Virtual memory exhausted");
+ PRINT_DEBUG("realloc: %d\n", size);
+ return value;
+}
+
+void
sighandler (int signum)
{
fprintf (stderr, "ratpoison: Agg! I've been SHOT!\n");
@@ -192,8 +218,8 @@ read_rc_file (FILE *file)
char *line;
int linesize = n;
- partial = (char*)malloc(n);
- line = (char*)malloc(linesize);
+ partial = (char*)xmalloc(n);
+ line = (char*)xmalloc(linesize);
*line = '\0';
while (fgets (partial, n, file) != NULL)
@@ -201,7 +227,7 @@ read_rc_file (FILE *file)
if ((strlen (line) + strlen (partial)) <= linesize)
{
linesize *= 2;
- line = (char*) realloc (line, linesize);
+ line = (char*) xrealloc (line, linesize);
}
strcat (line, partial);
@@ -245,7 +271,7 @@ read_startup_files ()
fprintf (stderr, "ratpoison: $HOME not set!?\n");
else
{
- char *filename = (char*)malloc (strlen (homedir) + strlen ("/.ratpoisonrc") + 1);
+ char *filename = (char*)xmalloc (strlen (homedir) + strlen ("/.ratpoisonrc") + 1);
sprintf (filename, "%s/.ratpoisonrc", homedir);
if ((fileptr = fopen (filename, "r")) == NULL)
@@ -359,11 +385,7 @@ main (int argc, char *argv[])
}
num_screens = ScreenCount (dpy);
- if ((screens = (screen_info *)malloc (sizeof (screen_info) * num_screens)) == NULL)
- {
- PRINT_ERROR ("Out of memory!\n");
- exit (EXIT_FAILURE);
- }
+ screens = (screen_info *)xmalloc (sizeof (screen_info) * num_screens);
PRINT_DEBUG ("%d screens.\n", num_screens);