]> granicus.if.org Git - php/commitdiff
- Implement CompareStringWithFile()
authorZeev Suraski <zeev@php.net>
Mon, 15 Jan 2001 15:13:50 +0000 (15:13 +0000)
committerZeev Suraski <zeev@php.net>
Mon, 15 Jan 2001 15:13:50 +0000 (15:13 +0000)
- Remove a stupid NULL assignment that slipped in the last commit

sapi/isapi/stresstest/stresstest.cpp

index 81b3773fa2a842175796a770b043052a4485b3e8..846305ac6c6a537dc186ddade3287b1e6a34814e 100644 (file)
@@ -97,12 +97,13 @@ void stripcrlf(char *line)
        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 @@ BOOL CompareFiles(const char*f1, const char*f2)
                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 @@ BOOL CompareFiles(const char*f1, const char*f2)
        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 @@ BOOL stress_main(const char *filename,
 
        // compare the output with the EXPECT section
        if (matchdata && *matchdata != 0) {
-               ok = CompareFiles(matchdata, fname);
+               ok = CompareStringWithFile(fname, matchdata, strlen(matchdata));
        }
 
        DeleteFile(fname);