diff options
Diffstat (limited to 'ext/standard/sha1.c')
-rw-r--r-- | ext/standard/sha1.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c index a408ac903..f72c73b37 100644 --- a/ext/standard/sha1.c +++ b/ext/standard/sha1.c @@ -16,9 +16,8 @@ +----------------------------------------------------------------------+ */ -/* $Id: sha1.c,v 1.9 2004/01/08 08:17:34 andi Exp $ */ +/* $Id: sha1.c,v 1.9.2.2 2005/04/16 09:50:13 thetaphi Exp $ */ -#include <stdio.h> #include "php.h" /* This code is heavily based on the PHP md5 implementation */ @@ -67,6 +66,7 @@ PHP_FUNCTION(sha1) /* }}} */ + /* {{{ proto string sha1_file(string filename [, bool raw_output]) Calculate the sha1 hash of given filename */ PHP_FUNCTION(sha1_file) @@ -79,40 +79,31 @@ PHP_FUNCTION(sha1_file) unsigned char digest[20]; PHP_SHA1_CTX context; int n; - FILE *fp; + php_stream *stream; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) { return; } - - if (PG(safe_mode) && (!php_checkuid(arg, NULL, CHECKUID_CHECK_FILE_AND_DIR))) { - RETURN_FALSE; - } - - if (php_check_open_basedir(arg TSRMLS_CC)) { - RETURN_FALSE; - } - - if ((fp = VCWD_FOPEN(arg, "rb")) == NULL) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file"); + + stream = php_stream_open_wrapper(arg, "rb", REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL); + if (!stream) { RETURN_FALSE; } PHP_SHA1Init(&context); - while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) { + while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) { PHP_SHA1Update(&context, buf, n); } PHP_SHA1Final(digest, &context); - if (ferror(fp)) { - fclose(fp); + php_stream_close(stream); + + if (n<0) { RETURN_FALSE; } - fclose(fp); - if (raw_output) { RETURN_STRINGL(digest, 20, 1); } else { |