dj(1): move open(2) flags, remove unnecessary comments

This commit is contained in:
dtb 2024-07-04 19:45:53 -06:00
parent f8c0e0570c
commit 8c33f0116c
Signed by: trinity
GPG Key ID: 34C0543BBB6AF81B

View File

@ -56,6 +56,9 @@ static char *fmt_human = "%d+%d > %d+%d; %d > %d\n";
static char *stdin_name = "<stdin>";
static char *stdout_name = "<stdout>";
static int creat_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH
| S_IWOTH; /* Consistent with touch(1p). */
static int read_flags = O_RDONLY; /* Consistent with Busybox dd(1). */
static int write_flags = O_WRONLY | O_CREAT;
@ -64,11 +67,6 @@ static int write_flags = O_WRONLY | O_CREAT;
/* Macro to check if fd is stdin or stdout */
#define fdisstd(fd) ((fd) == STDIN_FILENO || (fd) == STDOUT_FILENO)
/* Reads io->bs bytes from *io's file descriptor into io->buf, storing the
* number of read bytes in io->bufuse and updating io->bytes. If the buf isn't
* saturated but is still read into, io->prec will be incremented. If the buf
* is saturated, io->rec will be incremented. If io->bufuse is 0, errno will
* probably be set. Returns io. */
static struct Io *
Io_read(struct Io *io){
@ -84,9 +82,6 @@ Io_read(struct Io *io){
return io;
}
/* Writes io->bufuse (>0) units from io->buf to io->fd, permuting any unwritten
* bytes to the start of io->buf and updating io->bufuse. If io->bufuse doesn't
* change, errno will probably be set. Returns io. */
static struct Io *
Io_write(struct Io *io){
int t;
@ -190,10 +185,7 @@ int main(int argc, char *argv[]){
}else{
int fd;
if((fd = open(optarg, io[i].fl, /* touch(1p) flags */
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
| S_IROTH | S_IWOTH))
!= -1
if((fd = open(optarg, io[i].fl, creat_mode)) != -1
&& (fdisstd(io[i].fd) || close(io[i].fd) == 0)){
io[i].fd = fd;
io[i].fn = optarg;