K
Keith Thompson
Kleuske said:Don't. It's ineffective and may open up your system to abuse.
It's entirely effective (but non-portable, since the command string
you pass to system() is entirely system-specific).
As for abuse, that's a good point. If someone creates a pdf file
named, say, "foo ; rm -rf ~ ; bar.pdf", then incorporating that name
into the string you pass to system() could be really bad; see also
Little Bobby Tables, <http://xkcd.com/327/>. But if you're aware of
the problem, you can avoid it; if nothing else, you can just ignore
any files whose names contain any characters outside a safe set.
Somebody spent a great deal of time and effort writing an efficient
file copying command for your operating system. Why reinvent
the wheel?
Try fopen, fread, fwrite and fclose. Use a big buffer, since PDF's
(especially with grahics) tend to be big.
fread and fwrite do their own buffering. Copying a character at a time
is likely to be about as efficient as using a big buffer. (Don't take
my word for that; measure it!)
Check for error codes.
Such as the value returned by system().