From owner-freebsd-questions@FreeBSD.ORG Sun Dec 28 01:49:09 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8ECFF1065670 for ; Sun, 28 Dec 2008 01:49:09 +0000 (UTC) (envelope-from kline@thought.org) Received: from aristotle.thought.org (ns1.thought.org [209.180.213.210]) by mx1.freebsd.org (Postfix) with ESMTP id 445238FC17 for ; Sun, 28 Dec 2008 01:49:09 +0000 (UTC) (envelope-from kline@thought.org) Received: from thought.org (tao.thought.org [10.47.0.250]) (authenticated bits=0) by aristotle.thought.org (8.14.2/8.14.2) with ESMTP id mBS1ncMb073331; Sat, 27 Dec 2008 17:49:38 -0800 (PST) (envelope-from kline@thought.org) Received: by thought.org (nbSMTP-1.00) for uid 1002 kline@thought.org; Sat, 27 Dec 2008 17:49:03 -0800 (PST) Date: Sat, 27 Dec 2008 17:49:03 -0800 From: Gary Kline To: Giorgos Keramidas Message-ID: <20081228014903.GA82585@thought.org> 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k59lgu0k.fsf@kobe.laptop> User-Agent: Mutt/1.4.2.3i X-Organization: Thought Unlimited. Public service Unix since 1986. X-Of_Interest: With 22 years of service to the Unix community. X-Spam-Status: No, score=-4.4 required=3.6 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.2.3 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on aristotle.thought.org Cc: FreeBSD Mailing List Subject: Re: how can i be certain that a file has copied exactly? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 28 Dec 2008 01:49:09 -0000 On Sat, Dec 27, 2008 at 11:58:35PM +0200, Giorgos Keramidas wrote: > On Sat, 27 Dec 2008 13:35:51 -0800, Gary Kline 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 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