aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarstr\xf6m <john@ankarstrom.se>2021-05-31 20:38:07 +0200
committerJohn Ankarstr\xf6m <john@ankarstrom.se>2021-05-31 20:39:00 +0200
commitdebd03fa7cd6c133e61b89ba0ae48d9136055d77 (patch)
tree6760c20488db91c28663bb9343c19bb028a924bb
parentcfeaadbc88a707de8cbbfcd84316f49116df30da (diff)
downloadsafetitle-debd03fa7cd6c133e61b89ba0ae48d9136055d77.tar.gz
Fix error handling before "raw" mode
-rw-r--r--safetitle.c16
1 files 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;
}