92 lines
3.0 KiB
C
92 lines
3.0 KiB
C
/******************************************************************************
|
|
* Copyright © 2014-2019 The SuperNET Developers. *
|
|
* *
|
|
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
|
|
* the top-level directory of this distribution for the individual copyright *
|
|
* holder information and the developer policies on copyright and licensing. *
|
|
* *
|
|
* Unless otherwise agreed in a custom licensing agreement, no part of the *
|
|
* SuperNET software, including this file may be copied, modified, propagated *
|
|
* or distributed except according to the terms contained in the LICENSE file *
|
|
* *
|
|
* Removal or modification of this copyright notice is prohibited. *
|
|
* *
|
|
******************************************************************************/
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
|
|
#define true 1
|
|
#define false 0
|
|
#include "../../cJSON.c"
|
|
|
|
int32_t rogue_replay(uint64_t seed,int32_t sleeptime);
|
|
int rogue(int argc, char **argv, char **envp);
|
|
|
|
void *OS_loadfile(char *fname,uint8_t **bufp,long *lenp,long *allocsizep)
|
|
{
|
|
FILE *fp;
|
|
long filesize,buflen = *allocsizep;
|
|
uint8_t *buf = *bufp;
|
|
*lenp = 0;
|
|
if ( (fp= fopen(fname,"rb")) != 0 )
|
|
{
|
|
fseek(fp,0,SEEK_END);
|
|
filesize = ftell(fp);
|
|
if ( filesize == 0 )
|
|
{
|
|
fclose(fp);
|
|
*lenp = 0;
|
|
printf("OS_loadfile null size.(%s)\n",fname);
|
|
return(0);
|
|
}
|
|
if ( filesize > buflen )
|
|
{
|
|
*allocsizep = filesize;
|
|
*bufp = buf = (uint8_t *)realloc(buf,(long)*allocsizep+64);
|
|
}
|
|
rewind(fp);
|
|
if ( buf == 0 )
|
|
printf("Null buf ???\n");
|
|
else
|
|
{
|
|
if ( fread(buf,1,(long)filesize,fp) != (unsigned long)filesize )
|
|
printf("error reading filesize.%ld\n",(long)filesize);
|
|
buf[filesize] = 0;
|
|
}
|
|
fclose(fp);
|
|
*lenp = filesize;
|
|
//printf("loaded.(%s)\n",buf);
|
|
} //else printf("OS_loadfile couldnt load.(%s)\n",fname);
|
|
return(buf);
|
|
}
|
|
|
|
uint8_t *OS_fileptr(long *allocsizep,char *fname)
|
|
{
|
|
long filesize = 0; uint8_t *buf = 0; void *retptr;
|
|
*allocsizep = 0;
|
|
retptr = OS_loadfile(fname,&buf,&filesize,allocsizep);
|
|
return((uint8_t *)retptr);
|
|
}
|
|
|
|
int main(int argc, char **argv, char **envp)
|
|
{
|
|
uint64_t seed; FILE *fp = 0;
|
|
if ( argc == 2 && (fp=fopen(argv[1],"rb")) == 0 )
|
|
{
|
|
seed = atol(argv[1]);
|
|
fprintf(stderr,"replay %llu\n",(long long)seed);
|
|
return(rogue_replay(seed,50000));
|
|
}
|
|
else
|
|
{
|
|
if ( fp != 0 )
|
|
fclose(fp);
|
|
return(rogue(argc,argv,envp));
|
|
}
|
|
}
|
|
|
|
|