xscreen

X11 screenshot utility
git clone https://porkepik.fr/xscreen
Log | Files | Refs | README | LICENSE

commit 1144ccd0f96f2e533ba55a4065e578295d992bdd
parent e297f211e067fc763882f84ba1b949342c645506
Author: Thomas Philippe <dev@porkepik.fr>
Date:   Mon, 29 Jul 2019 16:13:01 +0200

replace failure() with errx()

Diffstat:
Mxscreen.c | 19++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/xscreen.c b/xscreen.c @@ -1,3 +1,4 @@ +#include <err.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -47,14 +48,6 @@ strend(const char *s, const char *t) } static void -failure(const char *err_str) -{ - fprintf(stderr, err_str); - XCloseDisplay(disp); - exit(EXIT_FAILURE); -} - -static void display_help(void) { printf("Usage: By default, takes a screenshot of the root window\n " @@ -78,7 +71,7 @@ check_args(int argc, char **argv, struct screenshot *img) case 'f': img->filename = malloc(strlen(optarg) + 1); if (!img->filename) - failure("malloc failure\n"); + errx(1, "malloc failure"); strcpy(img->filename, optarg); break; case 'd': @@ -123,7 +116,7 @@ make_default_filename(int format) char *filename = malloc(str_len + 5); if (!filename) - failure("malloc failure\n"); + errx(1, "malloc failure"); sprintf(filename, "screenshot_%d-%02d-%02d-%02d-%02d-%02d", date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, @@ -151,7 +144,7 @@ get_focused_window(void) XGetInputFocus(disp, &focused_win, &revert_to); if (!focused_win) - failure("No window is being focused.\n"); + errx(1, "No window is being focused."); return focused_win; } @@ -273,7 +266,7 @@ capture(Window win, struct screenshot *img) img->data = malloc(img->width * img->height * 3); if (!img->data) - failure("malloc failure\n"); + errx(1, "malloc failure"); switch (ximg->bits_per_pixel) { case 16: @@ -286,7 +279,7 @@ capture(Window win, struct screenshot *img) sg = 8; break; default: - failure("unsupported bits per pixel.\n"); + errx(1, "unsupported bpp: %d", ximg->bits_per_pixel); } for (int x = 0; x < img->width; x++) {