1
0
Fork 0
This commit is contained in:
dtb 2024-01-09 09:24:12 -07:00
parent 159f95a975
commit cb7e71989b
1 changed files with 15 additions and 13 deletions

28
dj/dj.c
View File

@ -49,26 +49,18 @@ struct Io{
* dj | 2 - typical output (default)
* dj -d | 3 - verbose status messages */
/* (-f) */ static char noerror; /* 0 - exits on partial reads or writes
/* (-n) */ static char noerror; /* 0 - exits on partial reads or writes
* (default)
* 1 - retries on partial reads/writes
* (-f) */
/* Non-configurable defaults. */
#define bs_default 1024
#define bs_default 1024 /* GNU dd(1) default; twice POSIX but a neat 2^10 */
static char *program_name = "<no argv[0]>";
static char *stdin_name = "<stdin>";
static char *stdout_name = "<stdout>";
static int read_flags = O_RDONLY;
static int write_flags = O_WRONLY | O_CREAT;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
/* Macro to check if fd is a std* file, e.g. stdin. */
#define fdisstd(fd) \
((fd) == STDIN_FILENO \
|| (fd) == STDOUT_FILENO \
|| (fd) == STDERR_FILENO)
static int read_flags = O_RDONLY; /* These flags are consistent with Busybox */
static int write_flags = O_WRONLY | O_CREAT; /* dd(1). */
/* Macro to set defaults for user-configurable options. */
#define setdefaults do{ \
@ -82,6 +74,14 @@ static int write_flags = O_WRONLY | O_CREAT;
ep[1].fl = write_flags; \
Io_setdefaults(&ep[1]); }while(0)
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
/* Macro to check if fd is a std* file, e.g. stdin. */
#define fdisstd(fd) \
((fd) == STDIN_FILENO \
|| (fd) == STDOUT_FILENO \
|| (fd) == STDERR_FILENO)
/* Macro to call the cleanup functions that operate on struct io on the
* particular io[2] used in main. Error conditions are not checked because this
* is only used when the program is about to terminate (hence its name). */
@ -320,7 +320,7 @@ int main(int argc, char *argv[]){
return oserr(optarg);
case 'A': align = '\0'; break;
case 'd': ++debug; break;
case 'f': noerror = 1; break;
case 'n': noerror = 1; break;
case 'H': fmt_output = fmt_human; break;
case 'q': --debug; break;
case 'a':
@ -328,6 +328,7 @@ int main(int argc, char *argv[]){
align = optarg[0];
break;
}
/* FALLTHROUGH */
case 'c': case 'b': case 's': case 'B': case 'S':
if(c == 'c' && (count = parse(optarg)) >= 0)
break;
@ -336,6 +337,7 @@ int main(int argc, char *argv[]){
if((c == 'b' && (ep[i].bs = parse(optarg)) > 0)
|| (c == 's' && (ep[i].seek = parse(optarg)) >= 0))
break;
/* FALLTHROUGH */
default:
terminate(ep);
return usage();