diff options
author | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-05-31 20:38:07 +0200 |
---|---|---|
committer | John Ankarstr\xf6m <john@ankarstrom.se> | 2021-05-31 20:39:00 +0200 |
commit | debd03fa7cd6c133e61b89ba0ae48d9136055d77 (patch) | |
tree | 6760c20488db91c28663bb9343c19bb028a924bb | |
parent | cfeaadbc88a707de8cbbfcd84316f49116df30da (diff) | |
download | safetitle-debd03fa7cd6c133e61b89ba0ae48d9136055d77.tar.gz |
Fix error handling before "raw" mode
-rw-r--r-- | safetitle.c | 16 |
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; } |