]> granicus.if.org Git - php/commitdiff
MFH: fix various solaris problems by replacing stdio with posix io where possible
authorUwe Schindler <thetaphi@php.net>
Fri, 15 Apr 2005 09:15:03 +0000 (09:15 +0000)
committerUwe Schindler <thetaphi@php.net>
Fri, 15 Apr 2005 09:15:03 +0000 (09:15 +0000)
ext/standard/md5.c
ext/standard/sha1.c

index 07e44bf151d0893c4610cf609a6214f228c54fb3..5e2410331f20588f06e9121dfc88ee262ce58274 100644 (file)
  * md5_file() added by Alessandro Astarita <aleast@capri.it>
  */
 
-#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 @@ 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_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
                WRONG_PARAM_COUNT;
@@ -89,24 +89,26 @@ PHP_NAMED_FUNCTION(php_if_md5_file)
                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);
index 420c349414e7bb2597b583a683533ec3fb64178a..a586afe0597b8cce79a91f70dc3359e81c1c8b36 100644 (file)
 
 /* $Id$ */
 
-#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 @@ 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_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
                WRONG_PARAM_COUNT;
@@ -87,25 +88,25 @@ PHP_FUNCTION(sha1_file)
                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);