Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Dec 2008 17:49:03 -0800
From:      Gary Kline <kline@thought.org>
To:        Giorgos Keramidas <keramida@freebsd.org>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: how can i be certain that a file has copied exactly?
Message-ID:  <20081228014903.GA82585@thought.org>
In-Reply-To: <87k59lgu0k.fsf@kobe.laptop>
References:  <20081227011335.GA29354@thought.org> <87ocyy2you.fsf@kobe.laptop> <20081227015634.GB29639@thought.org> <8763l61gbd.fsf@kobe.laptop> <20081227094012.GA39306@thought.org> <87zlihixlt.fsf@kobe.laptop> <20081227213551.GA75428@thought.org> <87k59lgu0k.fsf@kobe.laptop>

next in thread | previous in thread | raw e-mail | index | archive | help
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@thought.org> 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@thought.org> 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''
	main()'s.

	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

	

-- 
 Gary Kline  kline@thought.org  http://www.thought.org  Public Service Unix
        http://jottings.thought.org   http://transfinite.thought.org
    The 2.17a release of Jottings: http://jottings.thought.org/index.php




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20081228014903.GA82585>