zeev            Mon Jan 15 07:13:50 2001 EDT

  Modified files:              
    /php4/sapi/isapi/stresstest stresstest.cpp 
  Log:
  - Implement CompareStringWithFile()
  - Remove a stupid NULL assignment that slipped in the last commit
  
  
  
Index: php4/sapi/isapi/stresstest/stresstest.cpp
diff -u php4/sapi/isapi/stresstest/stresstest.cpp:1.10 
php4/sapi/isapi/stresstest/stresstest.cpp:1.11
--- php4/sapi/isapi/stresstest/stresstest.cpp:1.10      Mon Jan 15 06:55:30 2001
+++ php4/sapi/isapi/stresstest/stresstest.cpp   Mon Jan 15 07:13:50 2001
@@ -97,12 +97,13 @@
        if (line[l]==10 || line[l]==13) line[l]=0;
 }
 
+#define COMPARE_BUF_SIZE       1024
 
 BOOL CompareFiles(const char*f1, const char*f2)
 {
        FILE *fp1, *fp2;
        bool retval;
-       char buf1[1024], buf2[1024];
+       char buf1[COMPARE_BUF_SIZE], buf2[COMPARE_BUF_SIZE];
        int length1, length2;
 
        if ((fp1=fopen(f1, "r"))==NULL) {
@@ -119,7 +120,6 @@
                length1 = fread(buf1, 1, sizeof(buf1), fp1);
                length2 = fread(buf2, 1, sizeof(buf2), fp2);
 
-               buf2[0] = 0;
                // check for end of file
                if (feof(fp1)) {
                        if (!feof(fp2)) {
@@ -146,6 +146,39 @@
        return retval;
 }
 
+
+BOOL CompareStringWithFile(const char *filename, const char *str, unsigned int 
+str_length)
+{
+       FILE *fp;
+       bool retval;
+       char buf[COMPARE_BUF_SIZE];
+       unsigned int offset=0, readbytes;
+
+       if ((fp=fopen(filename, "r"))==NULL) {
+               return FALSE;
+       }
+
+       retval = TRUE; // success oriented
+       while (true) {
+               readbytes = fread(buf, 1, sizeof(buf), fp);
+
+               // check for end of file
+               if (feof(fp)) {
+                       break;
+               }
+
+               if (offset+readbytes > str_length
+                       || memcmp(buf, str+offset, readbytes)!=NULL) {
+                       retval = FALSE;
+                       break;
+               }
+       }
+       fclose(fp);
+
+       return retval;
+}
+
+
 BOOL ReadGlobalEnvironment(const char *environment)
 {
        if (environment) {
@@ -596,7 +629,7 @@
 
        // compare the output with the EXPECT section
        if (matchdata && *matchdata != 0) {
-               ok = CompareFiles(matchdata, fname);
+               ok = CompareStringWithFile(fname, matchdata, strlen(matchdata));
        }
 
        DeleteFile(fname);



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to