Hans Vlems said:
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 tocaller 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: (e-mail address removed) where j=john and f=forkosh)- Tekst uit oorspronkelijk bericht niet weergeven -
- Tekst uit oorspronkelijk bericht weergeven -- Tekst uit oorspronkelijk bericht niet weergeven -
- Tekst uit oorspronkelijk bericht weergeven -