From e3f2ade8bd960d9d2667aceeae5033df9814aba9 Mon Sep 17 00:00:00 2001 From: tumagonx Date: Mon, 31 Jul 2017 16:23:19 +0700 Subject: [PATCH] add split by number, more checks --- partfile.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/partfile.c b/partfile.c index 50b0855..63c91de 100644 --- a/partfile.c +++ b/partfile.c @@ -122,8 +122,9 @@ int main (int argc,char *argv[]) if (argc != 5) { printf ("Usage: %s [in] [out] [offset] [size]\n", argv[0]); printf ("replace [offset] with [-] to split input file\n"); - printf ("replace [size] with [-] to read remaining input file\n"); + printf ("replace [size] with [-] to read remaining input\n"); printf ("replace [out] with [-] to pipe output\n"); + printf ("in split mode, [size] < 4096 is number of pieces\n"); return -1; } @@ -157,7 +158,11 @@ int main (int argc,char *argv[]) } else outsize = _wtoi64 (wargv[4]); - if ((outsize <= 0) || (eof + split == 2)) { + + if ((outsize < 4096) && (split)) + outsize = (insize / outsize) + 1; + + if ((outsize <= 0) || (eof + split == 2) || (outsize < insize) || (outsize > (insize - initpos))) { printf ("Error: nothing to copy\n"); return -1; }