dj(1): more formatting

This commit is contained in:
Emma Tebibyte 2024-07-12 15:32:30 -06:00
parent 6cf7fd9794
commit db0dd02d55
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -138,9 +138,7 @@ static long parse(char *s){
errno = 0; errno = 0;
r = strtol(s, &s, 0); r = strtol(s, &s, 0);
return (*s == '\0' /* no chars left unparsed */ && errno == 0) return (*s == '\0' && errno == 0) ? r : -1; /* no chars left unparsed */
? r
: -1;
} }
static int usage(char *s){ static int usage(char *s){
@ -197,10 +195,10 @@ int main(int argc, char *argv[]) {
} else { } else {
int fd; int fd;
if (( if (
fd = open(optarg, io[i].fl, creat_mode)) != -1 (fd = open(optarg, io[i].fl, creat_mode)) != -1
&& (fdisstd(io[i].fd) || close(io[i].fd) == 0 && (fdisstd(io[i].fd) || close(io[i].fd) == 0)
)) { ) {
io[i].fd = fd; io[i].fd = fd;
io[i].fn = optarg; io[i].fn = optarg;
break; break;
@ -224,10 +222,10 @@ int main(int argc, char *argv[]) {
i = (c >= 'A' && c <= 'Z'); i = (c >= 'A' && c <= 'Z');
c |= 0b00100000; /* (ASCII) make lowercase */ c |= 0b00100000; /* (ASCII) make lowercase */
if(( if (
c == 'b' && (io[i].bs = parse(optarg)) > 0) (c == 'b' && (io[i].bs = parse(optarg)) > 0)
|| (c == 's' && (io[i].seek = parse(optarg)) >= 0 || (c == 's' && (io[i].seek = parse(optarg)) >= 0)
)) { break; } ) { break; }
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
@ -243,8 +241,10 @@ int main(int argc, char *argv[]) {
for (i = 0; i < (sizeof io) / (sizeof *io); ++i) { for (i = 0; i < (sizeof io) / (sizeof *io); ++i) {
/* buffer allocation */ /* buffer allocation */
if ((io[i].buf = malloc(io[i].bs * (sizeof *(io[i].buf)))) == NULL) { if ((io[i].buf = malloc(io[i].bs * (sizeof *(io[i].buf)))) == NULL) {
fprintf(stderr, "%s: Failed to allocate %zd bytes\n", fprintf(
program_name, io[i].bs); stderr, "%s: Failed to allocate %zd bytes\n",
program_name, io[i].bs
);
return EX_OSERR; return EX_OSERR;
} }