xscreenshot

screen capture tool (mirror)
git clone git://git.2f30.org/xscreenshot
Log | Files | Refs | README | LICENSE

commit d8f8fff9489a4e0521b682d2d9ab0698ad2b6422
parent e8fe465251d2897d54eaa451d9d653ff025a18e5
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Wed, 24 Feb 2016 20:00:25 +0100

use standard BSD err functions

add -D_BSD_SOURCE and -D_DEFAULT_SOURCE to cpp flags

Diffstat:
Mconfig.mk | 4++--
Mxscreenshot.c | 26++++++++------------------
2 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/config.mk b/config.mk @@ -17,11 +17,11 @@ LIBS = -L${X11LIB} -lX11 CPPFLAGS = -DVERSION=\"${VERSION}\" # debug -CFLAGS = -O0 -g -std=c99 -Wall -pedantic ${INCS} ${CPPFLAGS} +CFLAGS = -O0 -g -std=c99 -Wall -pedantic -D_DEFAULT_SOURCE -D_BSD_SOURCE ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} # optimized -#CFLAGS = -O2 -std=c99 -DVERSION=\"${VERSION}\" ${INCS} ${CPPFLAGS} +#CFLAGS = -O2 -std=c99 -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -D_BSD_SOURCE ${INCS} ${CPPFLAGS} #LDFLAGS = -s ${LIBS} # compiler and linker diff --git a/xscreenshot.c b/xscreenshot.c @@ -1,6 +1,7 @@ /* see LICENSE / README for more info */ #include <arpa/inet.h> +#include <err.h> #include <errno.h> #include <stdio.h> #include <stdint.h> @@ -11,20 +12,6 @@ #include <X11/Xlib.h> #include <X11/Xutil.h> -static void -die(const char *s) -{ - fprintf(stderr, "xscreenshot: %s\n", s); - exit(1); -} - -static void -usage(char **argv) -{ - fprintf(stderr, "usage: %s [winid]\n", argv[0]); - exit(1); -} - int main(int argc, char *argv[]) { @@ -37,13 +24,16 @@ main(int argc, char *argv[]) char *ep; if (!(dpy = XOpenDisplay(NULL))) - die("Can't XOpenDisplay"); + errx(1, "XOpenDisplay"); /* identify window */ if (argc > 1) { - if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-v") == 0) - usage(argv); + if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-v")) { + fprintf(stderr, "usage: %s [winid]\n", argv[0]); + return 1; + } errno = 0; + win = (Window)strtol(argv[1], &ep, 0); if (errno || argv[1] == ep || *ep != '\0') { fprintf(stderr, "strtol: invalid number: \"%s\"%s%s\n", @@ -82,7 +72,7 @@ main(int argc, char *argv[]) rgba[3] = htons(65535); if (fwrite(&rgba, 4 * sizeof(uint16_t), 1, stdout) != 1) - die("fwrite() failed"); + err(1, "fwrite"); } } XDestroyImage(img);