dj(1): remove Io_fdopen
This commit is contained in:
parent
2b593559af
commit
5b1d4fef88
35
src/dj.c
35
src/dj.c
|
@ -62,26 +62,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)
|
||||
|
||||
/* Opens io->fn and saves the file descriptor into io->fd. Returns io->fd,
|
||||
* which will be -1 if an error occured. */
|
||||
static int
|
||||
Io_fdopen(struct Io *io, char *fn){
|
||||
int fd;
|
||||
|
||||
assert(io != NULL);
|
||||
|
||||
if((fd = open(fn, io->fl,
|
||||
/* these are the flags used by touch(1p) */
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH))
|
||||
!= -1
|
||||
&& (fdisstd(io->fd) || close(io->fd) == 0)){
|
||||
io->fd = fd;
|
||||
io->fn = fn;
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
/* 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 io->bufuse is
|
||||
* 0, errno will probably be set. Returns io. */
|
||||
|
@ -159,8 +139,8 @@ int main(int argc, char *argv[]){
|
|||
int count; /* 0 if dj(1) runs until no more reads are possible */
|
||||
char *fmt; /* == fmt_asv (default) or fmt_human (-H) */
|
||||
size_t i; /* side of io being modified */
|
||||
struct Io io[2];
|
||||
char noerror; /* 0=exits (default) 1=retries on partial reads or writes */
|
||||
struct Io io[2];
|
||||
|
||||
/* Set defaults. */
|
||||
align = -1;
|
||||
|
@ -190,8 +170,19 @@ int main(int argc, char *argv[]){
|
|||
io[i].fd = i == 0 ? STDIN_FILENO : STDOUT_FILENO;
|
||||
io[i].fn = i == 0 ? stdin_name : stdout_name;
|
||||
break;
|
||||
}else if(Io_fdopen(&io[i], optarg) != -1)
|
||||
}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
|
||||
&& (fdisstd(io[i].fd) || close(io[i].fd) == 0)){
|
||||
io[i].fd = fd;
|
||||
io[i].fn = optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return oserr(optarg);
|
||||
case 'n': noerror = 1; break;
|
||||
case 'H': fmt = fmt_human; break;
|
||||
|
|
Loading…
Reference in New Issue
Block a user