how can i be certain that a file has copied exactly?

Gary Kline kline at
Sun Dec 28 01:49:09 UTC 2008

On Sat, Dec 27, 2008 at 11:58:35PM +0200, Giorgos Keramidas wrote:
> On Sat, 27 Dec 2008 13:35:51 -0800, Gary Kline <kline at> wrote:
> > On Sat, Dec 27, 2008 at 02:58:06PM +0200, Giorgos Keramidas wrote:
> >> On Sat, 27 Dec 2008 01:40:13 -0800, Gary Kline <kline at> wrote:
> >

		[[ save the electrons!]]

> > Your code copies flawlessly.  I noticed late last night that cmp uses
> > the same byte-by-byte cp and IIRC checks each to make certain they
> > bytes are identical.  My copyFile() function simply used fopen, fgets,
> > and fputs.  I yanked it from a program that copied files from ~/Mail
> > where the lines were around 80 bytes rather than in the thousands.
> > With few newlines.  The gotcha got me, in other words!  Thanks much
> > for the function!
> That's good news, because I didn't even compile it.  I just wrote it in
> my mailer and hit send.  I'm glad it worked :)
> For what it's worth, if you are not handling *text* files, fgets() and
> fputs() are probably a bad idea.  They are line oriented, and they
> depend on the presence of '\n' characters.  The concept of ``lines'' is,
> at best, ill defined for binary files.  So it makes more sense to use
> either byte-for-byte copies and rely on stdio to do buffering, or to use
> some sort of custom buffer and fread()/fwrite() or plain read()/write().

	Just got up from a nap [ and *coffee*].  Still, after last
	night's until past 03.30 with TWO giggling teenagers, god
	help me:)  --never had sleepover when i was 13--  Anyway,
	your comment about writing that from scratch brought to mind
	something I've been pondering recently.   I already have
	several kinds of main() functions that let you go in various
	directions.  Input by re-direction, input from the cmdline,
	even both.  These save me typing maybe 20 to 50 lines.  If
	you enjoy typing and rewriting code rom scratch a zillion
	times, fine, but at least I would rather use my ``prefab''

	I also have some very simple and efficient string-matching
	functions [[ for SHORT lines!! ]] and other thing we do very
	often.  It was (is?) throw-away code.  Does it made sense to
	have a place on the web where you can get these kind of
	canned functions?  I have perhaps 20 of these functions named
	and tagged.  This was, I believe, at least one idea behind
	C++, but at least I  have never seen any sites that offer C
	or C++ functions to do ``X''.



 Gary Kline  kline at  Public Service Unix
    The 2.17a release of Jottings:

More information about the freebsd-questions mailing list