MD5_CTX* context = get_md5_ctx(self);
STRLEN fill = context->bytes_low & 0x3F;
unsigned char buffer[4096];
- SSize_t n;
+ int n;
CODE:
if (fh) {
if (fill) {
* first.
*/
STRLEN missing = 64 - fill;
- n = PerlIO_read(fh, buffer, missing);
- if (n >= 0)
+ if ( (n = PerlIO_read(fh, buffer, missing)))
MD5Update(context, buffer, n);
else
XSRETURN(1); /* self */
}
/* Process blocks until EOF or error */
- while ( (n = PerlIO_read(fh, buffer, sizeof(buffer))) > 0 ) {
+ while ( (n = PerlIO_read(fh, buffer, sizeof(buffer)))) {
MD5Update(context, buffer, n);
}
- if (n < 0 && PerlIO_error(fh)) {
+ if (PerlIO_error(fh)) {
croak("Reading from filehandle failed");
}
}
fcc48d6bb88ca8065bf9ddfcb9e7483e Changes
0565ec21b15c0f23f4c51fb327c8926d README
1965beb0e48253b694220fbb5d6230f5 MD5.pm
-339e7a6915dcd67ff5bb583a7568fbb6 MD5.xs
+5b3c24da3f70f3c0938cc7c205a28ab7 MD5.xs
276da0aa4e9a08b7fe09430c9c5690aa rfc1321.txt
EOT
} elsif ("\n" eq "\015") { # MacOS
f161f474603c54a0093ad2f6f93be33b Changes
6c950a0211a5a28f023bb482037698cd README
18178c90bc13d6824f6c96973b6e9433 MD5.pm
-1f004206b000efac36e9890aac6f0281 MD5.xs
+2c7fdb2ffa3840dc4f8dcdcf13241015 MD5.xs
754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt
EOT
} else {
029fa5059ba0b2175cee09ab5d9b7b73 Changes
6c950a0211a5a28f023bb482037698cd README
18178c90bc13d6824f6c96973b6e9433 MD5.pm
-1f004206b000efac36e9890aac6f0281 MD5.xs
+2c7fdb2ffa3840dc4f8dcdcf13241015 MD5.xs
754b9db19f79dbc4992f7166eb0f37ce rfc1321.txt
EOT
}
else \
SETERRNO(EBADF, SS_IVCHAN)
-#define Perl_PerlIO_fail_if_hasnot(f, able, ueno, veno, ret) \
- if (PerlIOValid(f) && (PerlIOBase(f)->flags & (able)) == 0) { \
- PerlIOBase(f)->flags |= PERLIO_F_ERROR; \
- SETERRNO(ueno, veno); \
- return ret; \
- }
-
-#define Perl_PerlIO_fail_if_has(f, able, ueno, veno, ret) \
- if (PerlIOValid(f) && (PerlIOBase(f)->flags & (able)) == able) { \
- PerlIOBase(f)->flags |= PERLIO_F_ERROR; \
- SETERRNO(ueno, veno); \
- return ret; \
- }
-
int
perlsio_binmode(FILE *fp, int iotype, int mode)
{
SSize_t
Perl_PerlIO_read(pTHX_ PerlIO *f, void *vbuf, Size_t count)
{
- Perl_PerlIO_fail_if_hasnot(f, PERLIO_F_CANREAD, EBADF, SS_IVCHAN, -1);
Perl_PerlIO_or_Base(f, Read, read, -1, (aTHX_ f, vbuf, count));
}
SSize_t
Perl_PerlIO_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
{
- Perl_PerlIO_fail_if_hasnot(f, PERLIO_F_CANREAD, EBADF, SS_IVCHAN, -1);
Perl_PerlIO_or_Base(f, Unread, unread, -1, (aTHX_ f, vbuf, count));
}
SSize_t
Perl_PerlIO_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count)
{
- Perl_PerlIO_fail_if_hasnot(f, PERLIO_F_CANWRITE, EBADF, SS_IVCHAN, -1);
Perl_PerlIO_or_fail(f, Write, -1, (aTHX_ f, vbuf, count));
}
{
STDCHAR *buf = (STDCHAR *) vbuf;
if (f) {
+ if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD)) {
+ PerlIOBase(f)->flags |= PERLIO_F_ERROR;
+ SETERRNO(EBADF, SS_IVCHAN);
+ return 0;
+ }
while (count > 0) {
SSize_t avail = PerlIO_get_cnt(f);
SSize_t take = 0;
int fd = PerlIOSelf(f, PerlIOUnix)->fd;
if (!(PerlIOBase(f)->flags & PERLIO_F_CANREAD) ||
PerlIOBase(f)->flags & (PERLIO_F_EOF|PERLIO_F_ERROR)) {
- return -1;
+ return 0;
}
while (1) {
SSize_t len = PerlLIO_read(fd, vbuf, count);
IV
PerlIOUnix_seek(pTHX_ PerlIO *f, Off_t offset, int whence)
{
- int fd;
+ int fd = PerlIOSelf(f, PerlIOUnix)->fd;
Off_t new;
-#ifdef ESPIPE
- Perl_PerlIO_fail_if_has(f, PERLIO_F_NOTREG, ESPIPE, SS_IVCHAN, -1);
+ if (PerlIOBase(f)->flags & PERLIO_F_NOTREG) {
+#ifdef ESPIPE
+ SETERRNO(ESPIPE, LIB_INVARG);
#else
- Perl_PerlIO_fail_if_has(f, PERLIO_F_NOTREG, EBADF, SS_IVCHAN, -1);
+ SETERRNO(EINVAL, LIB_INVARG);
#endif
- fd = PerlIOSelf(f, PerlIOUnix)->fd;
- new = PerlLIO_lseek(fd, offset, whence);
+ return -1;
+ }
+ new = PerlLIO_lseek(fd, offset, whence);
if (new == (Off_t) - 1)
{
return -1;
IV
PerlIOStdio_error(pTHX_ PerlIO *f)
{
- IV stdio_error = PerlSIO_ferror(PerlIOSelf(f, PerlIOStdio)->stdio);
- /* Some stdio implementations do not mind e.g. trying to output
- * to a write-only filehandle, or vice versa. Therefore we will
- * try both the stdio way and the perlio way. */
- IV iobase_error = PerlIOValid(f) ?
- ((PerlIOBase(f)->flags & PERLIO_F_ERROR) != 0) : 0;
- return stdio_error || iobase_error;
+ return PerlSIO_ferror(PerlIOSelf(f, PerlIOStdio)->stdio);
}
void