From: Uwe Schindler Date: Fri, 15 Apr 2005 09:14:53 +0000 (+0000) Subject: MFH: fix various solaris problems by replacing stdio with posix io where possible X-Git-Tag: php-5.0.5RC1~432 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f809403a2d9fe0aa3aa8b492d37f53d493afd608;p=php MFH: fix various solaris problems by replacing stdio with posix io where possible --- diff --git a/ext/standard/md5.c b/ext/standard/md5.c index ef76ebf29d..18dcb089ab 100644 --- a/ext/standard/md5.c +++ b/ext/standard/md5.c @@ -23,9 +23,10 @@ * md5_file() added by Alessandro Astarita */ -#include #include "php.h" - +#include +#include +#include #include "md5.h" PHPAPI void make_digest(char *md5str, unsigned char *digest) @@ -80,8 +81,7 @@ PHP_NAMED_FUNCTION(php_if_md5_file) unsigned char buf[1024]; unsigned char digest[16]; PHP_MD5_CTX context; - int n; - FILE *fp; + int n,fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { return; @@ -95,25 +95,25 @@ PHP_NAMED_FUNCTION(php_if_md5_file) RETURN_FALSE; } - if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) { + if ((fd = VCWD_OPEN(arg, O_RDONLY)) == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file"); RETURN_FALSE; } PHP_MD5Init(&context); - while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) { + while ((n = read(fd, buf, sizeof(buf))) > 0) { PHP_MD5Update(&context, buf, n); } PHP_MD5Final(digest, &context); - if (ferror(fp)) { - fclose(fp); + if (n<0) { + close(fd); RETURN_FALSE; } - fclose(fp); + close(fd); if (raw_output) { RETURN_STRINGL(digest, 16, 1); diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c index a115e6fa9b..75b8c5fe89 100644 --- a/ext/standard/sha1.c +++ b/ext/standard/sha1.c @@ -18,8 +18,10 @@ /* $Id$ */ -#include #include "php.h" +#include +#include +#include /* This code is heavily based on the PHP md5 implementation */ @@ -78,8 +80,7 @@ PHP_FUNCTION(sha1_file) unsigned char buf[1024]; unsigned char digest[20]; PHP_SHA1_CTX context; - int n; - FILE *fp; + int n, fd; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { return; @@ -93,25 +94,25 @@ PHP_FUNCTION(sha1_file) RETURN_FALSE; } - if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) { + if ((fd = VCWD_OPEN(arg, O_RDONLY)) == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file"); RETURN_FALSE; } PHP_SHA1Init(&context); - while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) { + while ((n = read(fd, buf, sizeof(buf))) > 0) { PHP_SHA1Update(&context, buf, n); } PHP_SHA1Final(digest, &context); - if (ferror(fp)) { - fclose(fp); + if (n<0) { + close(fd); RETURN_FALSE; } - fclose(fp); + close(fd); if (raw_output) { RETURN_STRINGL(digest, 20, 1);