thetaphi Fri Apr 15 05:15:04 2005 EDT
Modified files: (Branch: PHP_4_3)
/php-src/ext/standard md5.c sha1.c
Log:
MFH: fix various solaris problems by replacing stdio with posix io where
possible
http://cvs.php.net/diff.php/php-src/ext/standard/md5.c?r1=1.28.4.1&r2=1.28.4.2&ty=u
Index: php-src/ext/standard/md5.c
diff -u php-src/ext/standard/md5.c:1.28.4.1 php-src/ext/standard/md5.c:1.28.4.2
--- php-src/ext/standard/md5.c:1.28.4.1 Tue Dec 31 11:35:31 2002
+++ php-src/ext/standard/md5.c Fri Apr 15 05:15:03 2005
@@ -16,16 +16,17 @@
+----------------------------------------------------------------------+
*/
-/* $Id: md5.c,v 1.28.4.1 2002/12/31 16:35:31 sebastian Exp $ */
+/* $Id: md5.c,v 1.28.4.2 2005/04/15 09:15:03 thetaphi Exp $ */
/*
* md5.c - Copyright 1997 Lachlan Roche
* md5_file() added by Alessandro Astarita <[EMAIL PROTECTED]>
*/
-#include <stdio.h>
#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)
@@ -72,8 +73,7 @@
unsigned char buf[1024];
unsigned char digest[16];
PHP_MD5_CTX context;
- int n;
- FILE *fp;
+ int n,fd;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE)
{
WRONG_PARAM_COUNT;
@@ -89,24 +89,26 @@
RETURN_FALSE;
}
- if ((fp = VCWD_FOPEN(Z_STRVAL_PP(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;
}
+ close(fd);
+
fclose(fp);
make_digest(md5str, digest);
http://cvs.php.net/diff.php/php-src/ext/standard/sha1.c?r1=1.3.4.1&r2=1.3.4.2&ty=u
Index: php-src/ext/standard/sha1.c
diff -u php-src/ext/standard/sha1.c:1.3.4.1 php-src/ext/standard/sha1.c:1.3.4.2
--- php-src/ext/standard/sha1.c:1.3.4.1 Tue Dec 31 11:35:34 2002
+++ php-src/ext/standard/sha1.c Fri Apr 15 05:15:03 2005
@@ -16,10 +16,12 @@
+----------------------------------------------------------------------+
*/
-/* $Id: sha1.c,v 1.3.4.1 2002/12/31 16:35:34 sebastian Exp $ */
+/* $Id: sha1.c,v 1.3.4.2 2005/04/15 09:15:03 thetaphi Exp $ */
-#include <stdio.h>
#include "php.h"
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
/* This code is heavily based on the PHP md5 implementation */
@@ -70,8 +72,7 @@
unsigned char buf[1024];
unsigned char digest[20];
PHP_SHA1_CTX context;
- int n;
- FILE *fp;
+ int n, fd;
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE)
{
WRONG_PARAM_COUNT;
@@ -87,25 +88,25 @@
RETURN_FALSE;
}
- if ((fp = VCWD_FOPEN(Z_STRVAL_PP(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);
make_sha1_digest(sha1str, digest);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php