elevator with layers

Rick Hohensee (humbubba@smarty.smart.net)
Wed, 18 Jul 2001 17:33:58 -0400 (EDT)


A guy posted some test results based on some code like this...

#include <stdio.h>
#include <assert.h>

#define TEST_SZ 25000000
#define RD_BUFF_SZ 5000
int main(int argc, const char **argv, const char **env)
{
FILE* fp;

if(argc > 1) fp = fopen(argv[1], "r+");
else fp =tmpfile();
if(NULL != fp) {
int j = -1;
int o;
while(1) {
if(++j != TEST_SZ) {
if (j == (TEST_SZ - RD_BUFF_SZ) ) o = ftello(fp);
fwrite(&j, sizeof(int), 1, fp);
} else {
int i, buffer[RD_BUFF_SZ];
fflush(fp);
fseek(fp, o, SEEK_SET);
fread(buffer, sizeof(int), sizeof(buffer), fp);
printf("Validating end of file writes\n");
for(i = (RD_BUFF_SZ - 1); i >= 0; i--) {
assert(buffer[i] == --j) ;
}
rewind(fp);
j = -1;
}
}
return 1;
}
return 0;
}

That's not it exactly. o wasn't an int. Probably a long long by some other
name. I don't know what he's trying to do with the above, but I believe
the following has the same basic action...

#include <stdio.h>
#include <assert.h>

int main () {

int i, j, buffer[5000], isize, bufsize;

isize = sizeof(int);
bufsize = sizeof(buffer);

FILE * stream = tmpfile();

top: j = -1;
fflush(stream);
fseek(stream, 0, SEEK_SET);
fread(buffer, isize, bufsize, stream);
printf("x ");
for(i = 4999; i >=0 ; i --) { assert(buffer[i] == --j) ; }
rewind(stream);
goto top ;
}

which should be a bit easier to assess if I'm right about what it's doing.
There's probably still some stuff there that can go away, but I'm not
familiar with rewind() and friends.

Rick Hohensee
www.clienux.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/