Alan Barrett <apb%cequrux.com@localhost> wrote: > On Thu, 31 May 2007, Jan Schaumann wrote: > > Modified Files: > > src/usr.bin/split: split.1 split.c > > > > Log Message: > > Add a new command-line option "-n chunk_count", that splits the input > > file into chunk_count smaller files. Each file will be size/chunk_count > > bytes large, with whatever spillover there is ending up in the chunk_counth > > file. > > If you change this line in split3() from > > split1(sb.st_size/chunks, chunks); > > to > > split1((sb.st_size + chunks - 1)/chunks, chunks); > > then the last file will never be larger than the others, there won't > be any "spillover", and you can remove all the new special cases in > split1(). If by "all the new special cases", you mean the counting of the files created, then I'm not sure if using your approach does the right thing. Consider a file of 100 bytes size that you want to split into 11 files: My approach says "split bytewise into files with 100/11 = 9 bytes, no more than 11 files" (ie 10 files with 9 bytes each, one file is 10 bytes, total # of files is 11). Your approach says "split bytewise into files with (100 + 11 - 1)/11 = 10 bytes" (ie 10 files with 10 bytes each). Or did you mean something else? -Jan -- Ancient Principle of WYGIWYGAINGW: What You Get Is What You're Given, And It's No Good Whining. --Terry Pratchett et al. (The Science of Discworld)
Attachment:
pgp4_cy3mdPGt.pgp
Description: PGP signature