PHP 4 NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 20??, Version 4.?.?
+- Changed sha1_file() / md5_file() to use streams instead of low level IO (Uwe)
- Added the sorting flag SORT_LOCALE_STRING to the sort() functions which makes
them sort based on the current locale. (Derick)
- Fixed bug #32699 (pg_affected_rows() was defined when it was not available).
*/
#include "php.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
#include "md5.h"
PHPAPI void make_digest(char *md5str, unsigned char *digest)
unsigned char buf[1024];
unsigned char digest[16];
PHP_MD5_CTX context;
- int n,fd;
+ int n;
+ php_stream *stream;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
convert_to_string_ex(arg);
- if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- RETURN_FALSE;
- }
-
- if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- if ((fd = VCWD_OPEN(Z_STRVAL_PP(arg), O_RDONLY)) == -1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file");
+ stream = php_stream_open_wrapper(Z_STRVAL_PP(arg), "rb", REPORT_ERRORS | ENFORCE_SAFE_MODE, NULL);
+ if (!stream) {
RETURN_FALSE;
}
PHP_MD5Init(&context);
- while ((n = read(fd, buf, sizeof(buf))) > 0) {
+ while ((n = php_stream_read(stream, buf, sizeof(buf))) > 0) {
PHP_MD5Update(&context, buf, n);
}
PHP_MD5Final(digest, &context);
+ php_stream_close(stream);
+
if (n<0) {
- close(fd);
RETURN_FALSE;
}
- close(fd);
-
make_digest(md5str, digest);
RETVAL_STRING(md5str, 1);
/* $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 */
unsigned char buf[1024];
unsigned char digest[20];
PHP_SHA1_CTX context;
- int n, fd;
+ int n;
+ php_stream *stream;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
WRONG_PARAM_COUNT;
convert_to_string_ex(arg);
- if (PG(safe_mode) && (!php_checkuid(Z_STRVAL_PP(arg), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- RETURN_FALSE;
- }
-
- if (php_check_open_basedir(Z_STRVAL_PP(arg) TSRMLS_CC)) {
- RETURN_FALSE;
- }
-
- if ((fd = VCWD_OPEN(Z_STRVAL_PP(arg), O_RDONLY)) == -1) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open file");
+ stream = php_stream_open_wrapper(Z_STRVAL_PP(arg), "rb", 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);
-
make_sha1_digest(sha1str, digest);
RETVAL_STRING(sha1str, 1);