Subject: | pread() and pwrite() problems |
Hi.
Consider below fragment of pread():
42 RETVAL = pread(PerlIO_fileno(fh), SvGROW(buf, len), len, offset);
43 SvCUR_set(buf, len);
44 SvTAINTED_on(buf);
System pread() call returns number of actually read bytes which can be less than requested, but line 43 sets buf length to value of len always. In particular, if pread() gets error, buf is not written at all, so will contain len bytes of rubbish on exit. 'tainted' flag should not be set in case of error too.
Consider below fragment of pwrite():
81 RETVAL = pwrite(PerlIO_fileno(fh), SvPV(buf, len), len, offset);
As 'perlguts' says: "Also remember that C doesn't allow you to safely say foo(SvPV(s, len), len);. It might work with your compiler, but it won't work for everyone".
So which value of len will go to pwrite() ? That passed through function argument (which can be less than length of buf) or assigned by SvPV macro?
Best regards!