/* parse arguments of write command */ static int runwrite(int argc, char **argv){ char *path = NULL; char *tstr = NULL; char *rstr = NULL; char *wstr = NULL; char *lstr = NULL; int omode = 0; bool rnd = false; for(int i = 2; i < argc; i++){ if(!path && argv[i][0] == '-'){ if(!strcmp(argv[i], "-nl")){ omode |= FDBONOLCK; } else if(!strcmp(argv[i], "-nb")){ omode |= FDBOLCKNB; } else if(!strcmp(argv[i], "-rnd")){ rnd = true; } else { usage(); } } else if(!path){ path = argv[i]; } else if(!tstr){ tstr = argv[i]; } else if(!rstr){ rstr = argv[i]; } else if(!wstr){ wstr = argv[i]; } else if(!lstr){ lstr = argv[i]; } else { usage(); } } if(!path || !tstr || !rstr) usage(); int tnum = tcatoix(tstr); int rnum = tcatoix(rstr); if(tnum < 1 || rnum < 1) usage(); int width = wstr ? tcatoix(wstr) : -1; int64_t limsiz = lstr ? tcatoix(lstr) : -1; int rv = procwrite(path, tnum, rnum, width, limsiz, omode, rnd); return rv; }
/* parse arguments of write command */ static int runwrite(int argc, char **argv){ char *name = NULL; char *tstr = NULL; char *rstr = NULL; for(int i = 2; i < argc; i++){ if(!name && argv[i][0] == '-'){ usage(); } else if(!name){ name = argv[i]; } else if(!tstr){ tstr = argv[i]; } else if(!rstr){ rstr = argv[i]; } else { usage(); } } if(!name || !tstr || !rstr) usage(); int tnum = tcatoix(tstr); int rnum = tcatoix(rstr); if(tnum < 1 || rnum < 1) usage(); int rv = procwrite(name, tnum, rnum); return rv; }