dj(1): move open(2) flags, remove unnecessary comments
This commit is contained in:
		
							parent
							
								
									f8c0e0570c
								
							
						
					
					
						commit
						8c33f0116c
					
				
							
								
								
									
										16
									
								
								src/dj.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								src/dj.c
									
									
									
									
									
								
							| @ -56,6 +56,9 @@ static char *fmt_human = "%d+%d > %d+%d; %d > %d\n"; | |||||||
| static char *stdin_name = "<stdin>"; | static char *stdin_name = "<stdin>"; | ||||||
| static char *stdout_name = "<stdout>"; | 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 read_flags = O_RDONLY; /* Consistent with Busybox dd(1). */ | ||||||
| static int write_flags = O_WRONLY | O_CREAT; | 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 */ | /* Macro to check if fd is stdin or stdout */ | ||||||
| #define fdisstd(fd) ((fd) == STDIN_FILENO || (fd) == STDOUT_FILENO) | #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 * | static struct Io * | ||||||
| Io_read(struct Io *io){ | Io_read(struct Io *io){ | ||||||
| 
 | 
 | ||||||
| @ -84,9 +82,6 @@ Io_read(struct Io *io){ | |||||||
| 	return 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 * | static struct Io * | ||||||
| Io_write(struct Io *io){ | Io_write(struct Io *io){ | ||||||
| 	int t; | 	int t; | ||||||
| @ -190,10 +185,7 @@ int main(int argc, char *argv[]){ | |||||||
| 				}else{ | 				}else{ | ||||||
| 					int fd; | 					int fd; | ||||||
| 
 | 
 | ||||||
| 					if((fd = open(optarg, io[i].fl, /* touch(1p) flags */ | 					if((fd = open(optarg, io[i].fl, creat_mode)) != -1 | ||||||
| 									S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |  | ||||||
| 										| S_IROTH | S_IWOTH)) |  | ||||||
| 								!= -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; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user