Jeff Abrahamson on Sat, 15 Jun 2002 02:50:16 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] unix cp function call (thanks)


On Fri, Jun 14, 2002 at 04:31:00PM -0400, Bill Jonas wrote:
> On Fri, Jun 14, 2002 at 04:26:56PM -0400, Walt Mankowski wrote:
> > Or you can call system(3).
> 
> Oh, right, there's that too, which is nicer and takes care of all that
> for you.  Can you tell I don't really do C all that much? ;-)

Security issues aside, don't forget that files can have holes. If you
want to be sophisticated about copying, you have to look at inodes and
stuff.

    /* Won't compile without correcting syntax */
    FILE *fp = fopen("/tmp/foo", "w");
    fputc('a', fp);
    fseek(fp, 10000000, SEEK_CUR);
    fputc('b', fp);
    fclose(fp);

I wrote two bytes, used two blocks (not counting inode, directory,
your copy could make a 10 MB file.

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>

 The Big Book of Misunderstanding, now in bookstores and on the web:
 <http://www.misunderstanding.net/buystuff.html>


______________________________________________________________________
Philadelphia Linux Users Group       -      http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug