Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #17438

Re: copying files

From JohnF <john@please.see.sig.for.email.com>
Newsgroups comp.lang.c
Subject Re: copying files
Date 2012-02-16 11:52 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <jhiqm2$r4n$1@reader1.panix.com> (permalink)
References <f62ccd5a-1cf4-4585-b8ca-c515a53d8a73@w9g2000vbv.googlegroups.com> <jhijf0$6lu$1@reader1.panix.com> <c93add96-9d72-4998-b8c2-62b9fee0a09d@hk10g2000vbb.googlegroups.com>

Show all headers | View raw


Hans Vlems <hvlems@freenet.de> wrote:
> JohnF <j...@please.see.sig.for.email.com> wrote:
>> Hans Vlems <hvl...@freenet.de> wrote:
>> > I'm maintaing large numbers of Adobe Reader files (.pdf). One of my
>> > programs, written in C (gcc 4.4.4), must make a copies between
>> > different filesystems of these pdf files.
>> > There is AFAIK no library function that does this, which leaves me two
>> > options:
>> > 1- use the console interface, i.e. build a command string and pass
>> > this to system().
>> > 2- open the file, copy the contents and close the target
>> > I'd rather avoid option 1 because system runs out of control of my
>> > program.
>> > My question is what read and write functions are best suited to copy
>> > the (binary) pdf files?
>> > 'Performance is not the main objective, but I want to be sure that the
>> > copy finished succesfully and accurately.
>> > Hans
>>
>> I'm guessing you're already aware of what Malcolm suggested
>> in preceding followup, and it's not adequate. And since I've
>> read your posts in comp.os.vms, I'm also guessing we're
>> talking about an ods-2/5 filesystem at one end, and maybe a
>> linux ext3, or whatever, at the other. Could you elaborate on
>> that a little? And does linux have some ods-2/5 support so you
>> can mount a vms disk? I wasn't aware of that. If you can indeed
>> just mount it, then by all means try Malcolm's suggestion and
>> see what happens. Should just work if the ods filesystem support
>> is any good. Otherwise, how are you intending to even access
>> the disk? Decnet for linux (note that it's no longer being
>> very actively supported)? I think that would be the driving
>> question that dictates an appropriate answer to your question.
>> So you need to supply all that additional info first.
>> ? ?By the way, I usually just ftp zipped files back and forth
>> between vms and linux boxes on my soho lan. Despite your
>> "out of control" issue, I'd just write a script (using C's
>> system() if you want the script in C) to do the job, unless
>> security's some really, really significant issue for your
>> situation.
>> --
>> John Forkosh ( mailto: j@f.com where j=john and f=forkosh )

> John,
> your investigating powers are impressive!
Indeed they are!
> Unfortunately they've led you into a dead end street...
Indeed they do!

> On a VMS system I wouldn't have had the need to ask a question. VMS
> has an IO subsystem (RMS) and a neatly documented API.
> And I doubt I'd have used C to solve this problem ;-) since I have a
> choice of at least 4 other languages that I'm more
> comfortable with...
> The project I'm involved in runs on a Windows platform, on Citrix
> servers more precisely and I have _no_ provileges on these
> systems. The reason I use the (old) DJGPP compiler is that doesn't
> need a Windows install process that uses the registry.
> The command line interface on WIndows doesn't even come close to what
> DCL has to offer. But I digress.
> 
> I want to copy pdf files from one windows disk to another, so the
> rename() function is useless. Next, I must retain the original file
> which is another reason why rename() won't do.
> C has a choice of functions to read from and write to diskfiles. I
> want to be sure that all content gets copied, unaltered and without
> inflating the file too much. One option is to read the input file one
> byte at a time and write it until EOF is signalled.
> Or read blocks, say 1 kB, and write them. Probably faster but may have
> other drawbacks I'm not aware of.
> The original post was written with this in mind and that was perhaps
> not too smart.
> Hans

Yeah, I've used djgpp and mingw to compile C programs on windows.
I think I'd recommend mingw if that works for you (I say "think"
because I can't recall >>why<< I prefer it). Anyway, when you say
>>no<< priviliges, I assume your program can read and write files,
i.e., whoever's running it has whatever's necessary to do that.
   In that case, block reads and writes are fine. I've done that
and it works okay for me. Of course, you should try it yourself,
since only God knows what'll happen in your particular situation.
But I think you can safely start with something of the form...

int	fcopy( char *infile, char *outfile ) {
FILE    *inptr = fopen(infile,"rb"),	/*open file for binary read*/
	*outptr = fopen(outfile,"wb");	/*and write*/
unsigned char buff[256];		/*block of bytes from infile*/
int     buflen=255, nread=0,nwrite=0,	/*#bytes we try to read/write*/
	nrw = 0;			/*total bytes read/written*/
if ( inptr!=NULL && outptr!=NULL ) {	/*have opened files*/
  while ( 1 ) {				/*read & write them till eof*/
    /* --- read bytes from infile --- */
    nread = fread(buff,sizeof(unsigned char),buflen,inptr); /*read*/
    if ( nread < 1 ) break;		/* no bytes left in file */
    /* --- write bytes to outfile --- */
    nwrite = fwrite(buff,sizeof(unsigned char),nread,outptr); /*write*/
    if ( nwrite != nread ) { nrw=(-1); break; } /*problem writing*/
    nrw += nwrite;			/*total #bytes*/
    if ( nread < buflen ) break;	/* no bytes left in file */
    } /* --- end-of-while(1) --- */
  fclose(inptr); fclose(outptr);	/* close files */
  } /* --- end-of-if(fileptrs!=NULL) --- */
return ( nrw );				/*back to caller with file size*/
} /* --- end-of-function fcopy() --- */

...which I've snipped from some code that works (with a few
essentially cosmetic changes so it reads okay as a code fragment).
-- 
John Forkosh  ( mailto:  j@f.com  where j=john and f=forkosh )

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 01:03 -0800
  Re: copying files Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-16 01:23 -0800
    Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 01:31 -0800
      Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 03:14 -0800
        Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 09:43 -0800
          Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 14:59 -0800
            Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 15:06 -0800
    Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 03:13 -0800
      Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 09:56 -0800
        Re: copying files Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-16 10:11 -0800
          Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 15:11 -0800
            Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 15:21 -0800
              Re: copying files Philip Lantz <prl@canterey.us> - 2012-02-17 09:53 -0800
                Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-18 07:22 -0800
            Re: copying files Malcolm McLean <malcolm.mclean5@btinternet.com> - 2012-02-17 03:36 -0800
              Re: copying files Willem <willem@toad.stack.nl> - 2012-02-17 22:04 +0000
                Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-18 07:28 -0800
                Re: copying files Willem <willem@toad.stack.nl> - 2012-02-18 21:28 +0000
              Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-18 07:19 -0800
        Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 15:02 -0800
  Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 01:34 -0800
    Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 03:27 -0800
      Re: copying files Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-02-16 17:11 +0000
        Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 14:57 -0800
      Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 09:54 -0800
    Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 06:41 -0800
  Re: copying files JohnF <john@please.see.sig.for.email.com> - 2012-02-16 09:49 +0000
    Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 03:10 -0800
      Re: copying files JohnF <john@please.see.sig.for.email.com> - 2012-02-16 11:52 +0000
        Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 06:56 -0800
          Re: copying files David Thompson <dave.thompson2@verizon.net> - 2012-02-24 04:43 -0500
        Re: copying files Ike Naar <ike@iceland.freeshell.org> - 2012-02-16 16:19 +0000
          Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 14:50 -0800
        Re: copying files David Thompson <dave.thompson2@verizon.net> - 2012-02-24 04:43 -0500
  Re: copying files Nobody <nobody@nowhere.com> - 2012-02-16 10:58 +0000
    Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 09:41 -0800
      Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 14:59 -0800
      Re: copying files Nobody <nobody@nowhere.com> - 2012-02-17 06:25 +0000
  Re: copying files Kleuske <kleuske@nowhere.net> - 2012-02-16 11:15 +0000
    Re: copying files Hans Vlems <hvlems@freenet.de> - 2012-02-16 06:45 -0800
    Re: copying files Keith Thompson <kst-u@mib.org> - 2012-02-16 09:49 -0800

csiph-web