public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* elevator with layers
@ 2001-07-18 21:33 Rick Hohensee
  0 siblings, 0 replies; only message in thread
From: Rick Hohensee @ 2001-07-18 21:33 UTC (permalink / raw)
  To: linux-kernel

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-07-18 21:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-07-18 21:33 elevator with layers Rick Hohensee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox