summaryrefslogtreecommitdiff
path: root/ext/standard/sha1.c
diff options
context:
space:
mode:
authorUwe Schindler <thetaphi@php.net>2005-04-15 14:29:32 +0000
committerUwe Schindler <thetaphi@php.net>2005-04-15 14:29:32 +0000
commit9cde55f8ed54a9c61452291aea29226d3e0c104b (patch)
treea7b8cbb44f337f89a2d4cad66f7e59ef48e4d76e /ext/standard/sha1.c
parentc4e788b03caf5eb7e80306f75e65f69c430d69a4 (diff)
downloadphp-git-9cde55f8ed54a9c61452291aea29226d3e0c104b.tar.gz
use streams api for md5_file and sha1_file. Added parameter use_include_path similar to other PHP file functions. Documentation update outstanding
Diffstat (limited to 'ext/standard/sha1.c')
-rw-r--r--ext/standard/sha1.c34
1 files changed, 13 insertions, 21 deletions
diff --git a/ext/standard/sha1.c b/ext/standard/sha1.c
index 75b8c5fe89..76675cee0d 100644
--- a/ext/standard/sha1.c
+++ b/ext/standard/sha1.c
@@ -19,9 +19,6 @@
/* $Id$ */
#include "php.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
/* This code is heavily based on the PHP md5 implementation */
@@ -69,51 +66,46 @@ PHP_FUNCTION(sha1)
/* }}} */
-/* {{{ proto string sha1_file(string filename [, bool raw_output])
+
+/* {{{ proto string sha1_file(string filename [, bool raw_output [, bool use_include_path]])
Calculate the sha1 hash of given filename */
PHP_FUNCTION(sha1_file)
{
char *arg;
int arg_len;
zend_bool raw_output = 0;
+ zend_bool use_include_path = 0;
char sha1str[41];
unsigned char buf[1024];
unsigned char digest[20];
PHP_SHA1_CTX context;
- int n, fd;
+ int n;
+ php_stream *stream;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &arg, &arg_len, &raw_output) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bb", &arg, &arg_len, &raw_output, &use_include_path) == 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 ((fd = VCWD_OPEN(arg, O_RDONLY)) == -1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file");
+
+ stream = php_stream_open_wrapper(arg, "rb",
+ (use_include_path ? USE_PATH : 0) | REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL);
+ if (!stream) {
RETURN_FALSE;
}
PHP_SHA1Init(&context);
- while ((n = read(fd, buf, sizeof(buf))) > 0) {
+ while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
PHP_SHA1Update(&context, buf, n);
}
PHP_SHA1Final(digest, &context);
+ php_stream_close(stream);
+
if (n<0) {
- close(fd);
RETURN_FALSE;
}
- close(fd);
-
if (raw_output) {
RETURN_STRINGL(digest, 20, 1);
} else {