diff options
author | Cem Keylan <cem@ckyln.com> | 2021-07-07 16:10:32 +0300 |
---|---|---|
committer | Cem Keylan <cem@ckyln.com> | 2021-07-07 16:10:32 +0300 |
commit | 854ddfac002e753a6389b48d3b9296fe32665ad3 (patch) | |
tree | ff9a2be83f68dd66239ff3a798222dc2f0afc9b8 /toys/posix/split.c | |
parent | 5bc00f0da395aa4ec779bb802bd78bf893565143 (diff) | |
parent | 3fbacb1f5c5eab1727d0bed0bd50d659af854ec7 (diff) | |
download | toybox-854ddfac002e753a6389b48d3b9296fe32665ad3.tar.gz |
Merge remote-tracking branch 'refs/remotes/origin/master'
Diffstat (limited to 'toys/posix/split.c')
-rw-r--r-- | toys/posix/split.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/toys/posix/split.c b/toys/posix/split.c index 5161affb..293343bf 100644 --- a/toys/posix/split.c +++ b/toys/posix/split.c @@ -22,7 +22,7 @@ config SPLIT -a Suffix length (default 2) -b BYTES/file (10, 10k, 10m, 10g...) -l LINES/file (default 1000) - -n PARTS + -n PARTS many equal length files */ #define FOR_split @@ -42,14 +42,10 @@ static void do_split(int infd, char *in) // posix doesn't cover permissions on output file, so copy input (or 0777) st.st_mode = 0777; + st.st_size = 0; fstat(infd, &st); - if (!TT.b && TT.n) { - if (lseek(infd, 0, SEEK_CUR) < 0) - error_exit("cannot determine file size"); - TT.b = st.st_size / TT.n; - } - + if (TT.n && (TT.b = st.st_size/TT.n)<1) return error_msg("%s: no size", in); len = pos = filenum = bytesleft = linesleft = 0; for (;;) { int i, j; @@ -70,9 +66,7 @@ static void do_split(int infd, char *in) j /= 26; } if (j) error_exit("bad suffix"); - bytesleft = TT.b; - if (TT.n && filenum == TT.n && st.st_size % 2) - ++bytesleft; + bytesleft = TT.b + ((filenum == TT.n) ? st.st_size%TT.n : 0); linesleft = TT.l; xclose(outfd); outfd = xcreate(TT.outfile, O_RDWR|O_CREAT|O_TRUNC, st.st_mode & 0777); |