From debd03fa7cd6c133e61b89ba0ae48d9136055d77 Mon Sep 17 00:00:00 2001 From: "John Ankarstr\\xf6m" Date: Mon, 31 May 2021 20:38:07 +0200 Subject: Fix error handling before "raw" mode --- safetitle.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/safetitle.c b/safetitle.c index ee37d3b..ee2a205 100644 --- a/safetitle.c +++ b/safetitle.c @@ -80,14 +80,10 @@ main(int argc, char *argv[]) } else goto usage; - if((ttyfd = open("/dev/tty", O_RDWR))==-1){ - fprintf(stderr, "could not open /dev/tty\n"); - goto end; - } - if((buf = malloc(200*sizeof(char)))==NULL){ - fprintf(stderr, "could not allocate memory\n"); - goto end; - } + if((ttyfd = open("/dev/tty", O_RDWR))==-1) + err(1, "open"); + if((buf = malloc(200*sizeof(char)))==NULL) + err(1, "malloc"); /* enter "raw" terminal mode */ tcgetattr(ttyfd, &restore); @@ -117,8 +113,8 @@ main(int argc, char *argv[]) r = 0; end: tcsetattr(ttyfd, TCSANOW, &restore); - exit(r); + return r; usage: fprintf(stderr, "usage: %s [-d] title\n", argv[0]); - exit(1); + return 1; } -- cgit v1.2.3