Example #1
0
/* we want to delete temporary files as early as possible */
static struct zfile *updateoutputfile (struct zfile *z)
{
    struct zfile *z2 = 0;
    int size;
    FILE *f = fopen (z->name, "rb");
    for (;;) {
	if (!f)
	    break;
        fseek (f, 0, SEEK_END);
	size = ftell (f);
	fseek (f, 0, SEEK_SET);
	if (!size)
	    break;
        z2 = zfile_fopen_empty (z->name, size);
	if (!z2)
	    break;
        fread (z2->data, size, 1, f);
	fclose (f);
	zfile_fclose (z);
	return z2;
    }
    if (f)
	fclose (f);
    zfile_fclose (z);
    zfile_fclose (z2);
    return 0;
}
BOOL LLXmlParser::parseFile(const std::string &path)
{
	llassert( !mDepth );
	
	BOOL success = TRUE;

	LLFILE* file = LLFile::fopen(path, "rb");		/* Flawfinder: ignore */
	if( !file )
	{
		mAuxErrorString = llformat( "Couldn't open file %s", path.c_str());
		success = FALSE;
	}
	else
	{
		S32 bytes_read = 0;
		
		fseek(file, 0L, SEEK_END);
		S32 buffer_size = ftell(file);
		fseek(file, 0L, SEEK_SET);

		void* buffer = XML_GetBuffer(mParser, buffer_size);
		if( !buffer ) 
		{
			mAuxErrorString = llformat( "Unable to allocate XML buffer while reading file %s", path.c_str() );
			success = FALSE;
			goto exit_label;
		}
		
		bytes_read = (S32)fread(buffer, 1, buffer_size, file);
		if( bytes_read <= 0 )
		{
			mAuxErrorString = llformat( "Error while reading file  %s", path.c_str() );
			success = FALSE;
			goto exit_label;
		}
		
		if( !XML_ParseBuffer(mParser, bytes_read, TRUE ) )
		{
			mAuxErrorString = llformat( "Error while parsing file  %s", path.c_str() );
			success = FALSE;
		}

exit_label: 
		fclose( file );
	}


	if( success )
	{
		llassert( !mDepth );
	}
	mDepth = 0;

	if( !success )
	{
		LL_WARNS() << mAuxErrorString << LL_ENDL;
	}

	return success;
}
Example #3
0
unsigned char *read_buffer(char *file_name, size_t *size_ptr)
{
        FILE *f;
        unsigned char *buf;
        size_t size;

        /* Open file */
        f = fopen(file_name, "rb");

        if (!f)
        return NULL;

        /* Obtain file size */
        fseek(f, 0, SEEK_END);
        size = ftell(f);
        fseek(f, 0, SEEK_SET);

        /* Allocate and read buffer */
        buf = malloc(size + 1);
        fread(buf, 1, size, f);
        buf[size] = '\0';

        /* Return size of buffer */
        if (size_ptr)
        *size_ptr = size;

        /* Return buffer */
        return buf;
}
Example #4
0
int TFInOut::GetSize() const {
  const int FPos = GetPos();
  IAssert(fseek(FileId, 0, SEEK_END) == 0);
  const int FLen = GetPos();
  IAssert(fseek(FileId, FPos, SEEK_SET) == 0);
  return FLen;
}
Example #5
0
// 暗号化されたファイルを読み込んで、_Output内に格納
bool CKakusi::ModosiFile( char* _Filename, unsigned char* _Output )
{
	FILE* _fp;
	unsigned char *pBuffer = NULL;
	bool ret;

	try {
		if (fopen_s(&_fp, _Filename, "rb")) return false;

		// file size
		long size = 0;
		fseek( _fp, 0, SEEK_END );
		size = ftell( _fp );
		fseek( _fp, 0, SEEK_SET );
		if ( size <= 0 ) {
			fclose( _fp );
			return false;
		}		

		pBuffer = new unsigned char[size];

		fread(pBuffer, size, 1, _fp);

		kakusibako.Decrypt(pBuffer, _Output, size);

		ret = true;
	} catch(...) {
		ret = false;
	}

	if (_fp) fclose( _fp );
	delete [] pBuffer;
	return ret;
}
Example #6
0
size_t pocl_file_size(FILE* file) {
    size_t size;
    fseek(file, 0, SEEK_END);
    size = (size_t)ftell(file);
    fseek(file, 0, SEEK_SET);
    return size;
}
Example #7
0
Maze *Read_maze_from_2Dfile(FILE *fptr)
{
  fseek(fptr,0,SEEK_SET);
  int nrow = 0;
  int ncol = 0;
  char ch;
  while((ch=fgetc(fptr)) != EOF){
    if(ch=='\n')
      nrow++;
    if(nrow==0)
      ncol++;
  }
  Maze *pointerMaze = Allocate_maze_space(nrow,ncol);
  if(pointerMaze == NULL){
    Deallocate_maze_space(pointerMaze);
    return NULL;  
  }
  else{ 
    int i;   
    int j;
    fseek(fptr,0,SEEK_SET);
    for(i = 0; i < nrow; i++){
      for(j = 0; j < ncol; j++){
        ch = get_loc_type(fptr,i,j);
          pointerMaze->maze_array[i][j] = ch;
      }
    } 
  }
  return pointerMaze;
}
Example #8
0
//-----------------------------------------------------------------------------
// GetParameters() extracts fp, nbit, wav_length from the .wav file
// This function is only used in wavread().
//-----------------------------------------------------------------------------
static bool GetParameters(FILE *fp, int *fs, int *nbit, int *wav_length) {
  char data_check[5] = {0};
  data_check[4] = '\0';
  unsigned char for_int_number[4];
  fread(for_int_number, 1, 4, fp);
  *fs = 0;
  for (int i = 3; i >= 0; --i) *fs = *fs * 256 + for_int_number[i];
  // Quantization
  fseek(fp, 6, SEEK_CUR);
  fread(for_int_number, 1, 2, fp);
  *nbit = for_int_number[0];

  // Skip until "data" is found. 2011/03/28
  while (0 != fread(data_check, 1, 1, fp)) {
    if (data_check[0] == 'd') {
      fread(&data_check[1], 1, 3, fp);
      if (0 != strcmp(data_check, "data")) {
        fseek(fp, -3, SEEK_CUR);
      } else {
        break;
      }
    }
  }
  if (0 != strcmp(data_check, "data")) {
    printf("data error.\n");
    return false;
  }

  fread(for_int_number, 1, 4, fp);  // "data"
  *wav_length = 0;
  for (int i = 3; i >= 0; --i)
    *wav_length = *wav_length * 256 + for_int_number[i];
  *wav_length /= (*nbit / 8);
  return true;
}
Example #9
0
// size of file
int sizefile(FILE *f){
  int prev = ftell(f);
  fseek(f,(long)0,SEEK_END);
  int size = ftell(f);
  fseek(f,prev,SEEK_SET);
  return size;
}
Example #10
0
cJSON* hhmpc_dynmem_get_data (char *fname)
{
    cJSON *data;
    char *fdata;
    FILE *f=fopen(fname,"rb");
    if (NULL == f) {
        printf("ERROR: could not open file %s \n", fname);
        return NULL;
    }
    
    fseek(f,0,SEEK_END);
    long len=ftell(f);
    fseek(f,0,SEEK_SET);
    fdata=(char*)malloc(len+1);
    if (NULL == fdata) {
        printf("ERROR: could not allocate memory for file %s \n", fname);
        return NULL;
    }
    
    fread(fdata,1,len,f);
    fclose(f);
    data = cJSON_Parse(fdata);
    free(fdata);
    if (NULL == data) {
        printf("ERROR: could not parse file %s \n", fname);
        return NULL;
    }
    
    return data;
}
// Check whether need to recovery, if yes, reset fseek to the right place.
bool WriteBehindFrontendLogger::NeedRecovery(void) {
  // Otherwise, read the last transaction record
  fseek(log_file, -TransactionRecord::GetTransactionRecordSize(), SEEK_END);

  // Get its type
  auto log_record_type = GetNextLogRecordType(log_file, log_file_size);

  // Check if the previous transaction run is broken
  if (log_record_type == LOGRECORD_TYPE_TRANSACTION_COMMIT) {
    TransactionRecord txn_record(LOGRECORD_TYPE_TRANSACTION_COMMIT);

    // read the last written out transaction log record
    if (ReadTransactionRecordHeader(txn_record, log_file, log_file_size) ==
        false) {
      return false;
    }

    // Peloton log records items have fixed size.
    // Compute log offset based on txn_id
    size_t tuple_log_record_count = txn_record.GetTransactionId();

    size_t rollback_offset =
        tuple_log_record_count * TupleRecord::GetTupleRecordSize() +
        TransactionRecord::GetTransactionRecordSize();

    // Rollback to the computed offset
    fseek(log_file, -rollback_offset, SEEK_END);
    return true;
  } else {
    return false;
  }
}
Example #12
0
/*
Calculates the size of file
Returns size of the file
*/
int get_file_size(FILE* pfile)
{
	fseek(pfile, 0, SEEK_END);
	int Size = ftell(pfile);
	fseek(pfile, 0, SEEK_SET);
	return Size;
}
Example #13
0
void list (char archivename[30]) {
    FILE *o;int i,decimal,octal;
    union record aux;
    o=fopen(archivename,"rt");
    if (o) {
    while (fread(&aux,sizeof(union record),1,o) ) {
        /* Dupa ce header-ul primului fisier arhivat a fost citit,se poate afisa
           numele acestui fisier */
        printf("%s\n",aux.header.name);
        // Se retine dimensiunea fisierului si se transforma in zecimal
        octal=atoi (aux.header.size);
        decimal=0;i=0;
        while(octal!=0)
        {
            decimal = decimal + (octal % 10) * pow(8,i++);
            octal = octal/10;
        }
        /* Daca continutul fisierului a reusit sa fie cuprins intr-un nr de blocuri
            complete,se trece pur si simplu peste caracterele reprezentand continutul
            fisierului, daca nu se trece si peste caracterele '\0' folosite pentru
            a umple complet blocurile */
        if (decimal % 512!=0)
        {
            fseek(o,(decimal/512 + 1)*512 , SEEK_CUR);
        }
        else {
                fseek(o,decimal,SEEK_CUR); 
             }   

    }
    fclose(o); 
    }
}
Example #14
0
unsigned int XMLPlatformUtils::fileSize(FileHandle theFile
                                        , MemoryManager* const manager)
{
    // Get the current position
    long  int curPos = ftell((FILE*) theFile);
    if (curPos == -1)
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::File_CouldNotGetCurPos, manager);

    // Seek to the end and save that value for return
     if (fseek((FILE*) theFile, 0, SEEK_END))
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::File_CouldNotSeekToEnd, manager);

    long int retVal = ftell((FILE*)theFile);
    if (retVal == -1)
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::File_CouldNotSeekToEnd, manager);

    // And put the pointer back

    if (fseek( (FILE*)theFile, curPos, SEEK_SET) )
        ThrowXMLwithMemMgr(XMLPlatformUtilsException,
                 XMLExcepts::File_CouldNotSeekToPos, manager);

    return (unsigned int)retVal;
}
Example #15
0
unsigned long calc_file_size(){
	//Get file length
	fseek(file, 0, SEEK_END);
	unsigned long len=ftell(file);
	fseek(file, 0, SEEK_SET);
	return len;
}
int hapsLocusFile::readHeaderInfo()
{
	int i,s;
	char *ptr;
	fseek(fp,0,SEEK_SET);
	if (!fgets(locusFile::buff,BUFFSIZE-1,fp))
	{
		dcerror(99,"Could not read first line of HAPS file");
		return 0;
	}
	for (ptr=locusFile::buff,s=0;s<5;++s)
	{
		while (!isspace(*ptr))
			++ptr;
		while (isspace(*ptr))
			++ptr;
		if (*ptr=='\0')
			break; // end of line with no entries
	}
	nSubs=0;
	for (;*ptr;++nSubs) // count subjects - each is one pair of alleles
	{
		while (!isspace(*ptr))
			++ptr;
		while (isspace(*ptr))
			++ptr;
		while (!isspace(*ptr))
			++ptr;
		while (isspace(*ptr))
			++ptr;
	}
	fseek(fp,0,SEEK_SET); // be ready to read the first locus
	return nSubs;
}
Example #17
0
Node *getListOfReservedWords(char *fptrw){//fptrw= file path to reserved words
	Node *lrw=NULL;//list reserved words
	char *word,*token;
	if((el=fopen(fptrw,"r"))==NULL){
		return NULL;
	}
	sl=fopen(fptrw,"r");
	while((cr=fgetc(el))!=EOF){
		while(cr!='\n' && cr!=EOF){
			cr=fgetc(el);
		}
		fseek(el,-1,SEEK_CUR);
		setLexema();//set lexema reconocido on global variable lexema
		fgetc(el);
		fseek(sl,ftell(el),SEEK_SET);
		word=strdup(strtok(lexema,"|"));
		token=strdup(strtok(NULL,"|"));
		//printf("word= |%s|\n",word);
		//printf("token= |%s|\n",token);
		addNode(&lrw,getNode(word,token,NULL,NULL));
	}
	fclose(sl);
	fclose(el);
	return lrw;
}
Example #18
0
static int file_length( FILE *fp )
{
	int length = 0;
    int res = fseek( fp, 0, SEEK_END );
	if ( res == 0 )
	{
		long long_len = ftell( fp );
		if ( long_len > INT_MAX )
        {
			fprintf( stderr,"mvdfile: file too long: %ld", long_len );
            length = res = 0;
        }
		else
        {
            length = (int) long_len;
            if ( length != -1 )
                res = fseek( fp, 0, SEEK_SET );
            else
                res = 1;
        }
	}
	if ( res != 0 )
    {
		fprintf(stderr, "encoding: failed to read file. error %s\n",
            strerror(errno) );
        length = 0;
    }
	return length;
}
Example #19
0
void hsBufferedStream::Skip(uint32_t delta)
{
    if (fWriteBufferUsed)
    {
        // buffered write not implemented yet.
        fseek(fRef, delta, SEEK_CUR);
    }
    else
    {
        uint32_t blockStart = ((fPosition + delta) / kBufferSize) * kBufferSize;

        // We've got data in the buffer, see if we can just skip in that
        if (fBufferLen > 0)
        {
            int32_t newBufferPos = int32_t(fPosition % kBufferSize) + int32_t(delta);

            // If we skipped outside of our buffer, invalidate it
            if (newBufferPos < 0 || uint32_t(newBufferPos) >= fBufferLen)
            {
                fBufferLen = 0;
                fseek(fRef, blockStart, SEEK_SET);
            }
        }
        else
            fseek(fRef, blockStart, SEEK_SET);
    }

    fPosition += delta;
}
Example #20
0
	void InPlaceParser::SetFile(const char *fname)
	{
		if ( mMyAlloc )
		{
			free(mData);
		}
		mData = 0;
		mLen  = 0;
		mMyAlloc = false;

		FILE *fph = fopen(fname,"rb");
		if ( fph )
		{
			fseek(fph,0L,SEEK_END);
			mLen = ftell(fph);
			fseek(fph,0L,SEEK_SET);

			if ( mLen )
			{
				mData = (char *) malloc(sizeof(char)*(mLen+1));
				int32 read = (int32)fread(mData,mLen,1,fph);
				if ( !read )
				{
					free(mData);
					mData = 0;
				}
				else
				{
					mData[mLen] = 0; // zero byte terminate end of file marker.
					mMyAlloc = true;
				}
			}
			fclose(fph);
		}
	}
Example #21
0
WRes File_GetLength(CSzFile *p, UInt64 *length)
{
  #ifdef USE_WINDOWS_FILE
  
  DWORD sizeHigh;
  DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
  if (sizeLow == 0xFFFFFFFF)
  {
    DWORD res = GetLastError();
    if (res != NO_ERROR)
      return res;
  }
  *length = (((UInt64)sizeHigh) << 32) + sizeLow;
  return 0;
  
  #else
  
  long pos = ftell(p->file);
  int res = fseek(p->file, 0, SEEK_END);
  *length = ftell(p->file);
  fseek(p->file, pos, SEEK_SET);
  return res;
  
  #endif
}
/*从文件读取cJSON结构*/
cJSON* GetJsonObjectFormfile(char* fileName)
{
    long len;
    char* pContent;
    int tmp;
    cJSON* json;
    FILE* fp = fopen(fileName, "r+");
    CHNLGPE_1Print("GetJsonObjectFormfile: Reading file : %s.\n",(Uint32)fileName);
    json = cJSON_CreateObject();
    if(!fp)
    {
        return NULL;
    }
    fseek(fp,0,SEEK_END);
    len=ftell(fp);
    if(0 == len)
    {

    		printf("no length\n");
        return NULL;
    }
    fseek(fp,0,SEEK_SET);
    pContent = (char*) malloc (sizeof(char)*len);
    tmp = fread(pContent,1,len,fp);
    fclose(fp);
    json=cJSON_Parse(pContent);
    if (!json)
    {
        return NULL;
    }
    free(pContent);
    return json;
}
Example #23
0
struct benchmark_res_html benchmark_load_html_file(const char* filename)
{
    FILE *fh = fopen(filename, "rb");
    if(fh == NULL) {
        fprintf(stderr, "Can't open html file: %s\n", filename);
        exit(EXIT_FAILURE);
    }
    
    fseek(fh, 0L, SEEK_END);
    long size = ftell(fh);
    fseek(fh, 0L, SEEK_SET);
    
    char *html = (char*)malloc(size + 1);
    if(html == NULL) {
        DIE("Can't allocate mem for html file: %s\n", filename);
    }
    
    size_t nread = fread(html, 1, size, fh);
    if (nread != size) {
        DIE("could not read %ld bytes (%zu bytes done)\n", size, nread);
    }
    
    fclose(fh);
    
    if(size < 0) {
        size = 0;
    }
    
    struct benchmark_res_html res = {html, (size_t)size};
    return res;
}
Example #24
0
/* Throws out all entries marked as unused, by walking through the
 * filedb and moving all good ones towards the top.
 */
static void filedb_cleanup(FILE *fdb)
{
    long oldpos, newpos, temppos;
    filedb_entry *fdbe = NULL;

    filedb_readtop(fdb, NULL);    /* Skip DB header  */
    newpos = temppos = oldpos = ftell(fdb);
    fseek(fdb, oldpos, SEEK_SET); /* Go to beginning */
    while (!feof(fdb)) {          /* Loop until EOF  */
        fdbe = filedb_getfile(fdb, oldpos, GET_HEADER);     /* Read header     */
        if (fdbe) {
            if (fdbe->stat & FILE_UNUSED) {   /* Found dirt!     */
                free_fdbe(&fdbe);
                while (!feof(fdb)) {    /* Loop until EOF  */
                    newpos = ftell(fdb);
                    fdbe = filedb_getfile(fdb, newpos, GET_FULL); /* Read next entry */
                    if (!fdbe)
                        break;
                    if (!(fdbe->stat & FILE_UNUSED)) {    /* Not unused?     */
                        temppos = ftell(fdb);
                        filedb_movefile(fdb, oldpos, fdbe); /* Move to top     */
                        oldpos = ftell(fdb);
                        fseek(fdb, temppos, SEEK_SET);
                    }
                    free_fdbe(&fdbe);
                }
            } else {
                free_fdbe(&fdbe);
                oldpos = ftell(fdb);
            }
        }
    }
    ftruncate(fileno(fdb), oldpos);       /* Shorten file    */
}
Example #25
0
int main(int argc,char **argv) {
  FILE *fin; int limit,blen=0,p,l,bcnt=0; unsigned char *buf=NULL;
  assert(argc >= 2);
  sprintf(filename,"/Library/Dictionaries/%s.dictionary/Contents/Body.data",argv[1]);
  if((fin=fopen(filename,"rb"))) {
    fseek(fin,0x40,SEEK_SET);
    fread(&l,1,4,fin);
    limit=0x40+l;
    p=0x60;
    do {
      fseek(fin,p,SEEK_SET);
      fread(&l,1,4,fin);
//      if(0==l) break;
      if(blen<l) {
        if(buf!=NULL) free(buf);
        blen=l;
        buf=(unsigned char *)malloc(blen);
      }
      fread(buf,1,l,fin);
      //fprintf(stderr, "%x@%06x: %x>%06x\n",bcnt,p,l,((int *)buf)[1]);
      unpack(buf+8,l-8);
      p+=4+l;
      ++bcnt;
    } while(p<limit);
    free(buf);
    fclose(fin);
  }
  return 0;
}
int main()
{
    int i;
    int num[MAX];                            //存放10个数
    char str[LEN];                           //读取,写入文件缓冲
    FILE *fp;                                //文件指针

    fp = fopen("number","w+");

    if(fp == NULL)
    {
        printf("fopen file error !\n");
        exit(ERROR);
    }
 
    num_to_file(fp);                         //将数写入文件

    fseek(fp,0,SEEK_SET);
    fgets(str,LEN,fp);
    printf("the old num : %s\n",str);        //打印出文件内容

    fseek(fp,0,SEEK_SET);
    file_to_num(fp,num);                     //将文件读出并转换成数组
     
    order_num(num);                          //对数组进行排序
 
    fseek(fp,0,SEEK_SET);
    order_to_file(fp,num);                   //将新数组写入文件

    fseek(fp,0,SEEK_SET);
    fgets(str,LEN,fp);                       //读出文件并打印出文件内容
    printf("the ordering num : %s\n",str);  

    return 0;
}
Example #27
0
static int load_file_to_memory(const char *filename, char **result) {
	unsigned int size;

	FILE *f = fopen(filename, "rb");
	if (f == NULL) {
		*result = NULL;
		printf("Error: Could not read file %s\n", filename);
		exit(EXIT_FAILURE);
	}

	fseek(f, 0, SEEK_END);
	size = ftell(f);
	fseek(f, 0, SEEK_SET);

	*result = (char *) smalloc(sizeof(char)*(size+1));

	if (size != fread(*result, sizeof(char), size, f)) {
		free(*result);
		printf("Error: read of kernel failed\n");
		exit(EXIT_FAILURE);
	}

	fclose(f);
	(*result)[size] = 0;

	return size;
}
Example #28
0
bool NDSSYSTEM::nds_loadfile(const char *fpath)
{
    struct nds_header_t header;
    rom = fopen(fpath, "rb");
    if( !rom )
        return false;
    else{
        fseek(rom, 0, SEEK_SET);
        fread(&header, sizeof(struct nds_header_t), sizeof(u8), rom);
        fseek(rom, header.ARM9rom_offset, SEEK_SET);

        /* Arm9 program */
        fread(mmu->memory, header.ARM9size, sizeof(u8), rom);
        memcpy(&mmu->memory[0x400000], mmu->memory, sizeof(u8)*0x400000);
        memcpy(&mmu->memory[0x800000], mmu->memory, sizeof(u8)*0x400000);
        memcpy(&mmu->memory[0xC00000], mmu->memory, sizeof(u8)*0x400000);

        /* Header */
        memcpy(&mmu->memory[0x7FFFE0], &header, sizeof(struct nds_header_t) );

        cpu->m_newpc = header.ARM9entry_adress;
        cpu->m_r[15] = header.ARM9entry_adress;

        cpu->arm9_entry = cpu->m_newpc;
        cpu->arm7_entry = header.ARM9entry_adress;

        cpu->arm9size = header.ARM9size;
        cpu->arm7size = header.ARM7size;

        return true;
    }
    return false;
}
Example #29
0
static const GLchar*
ReadShader( const char* filename )
{
#ifdef WIN32
	FILE* infile;
	fopen_s( &infile, filename, "rb" );
#else
    FILE* infile = fopen( filename, "rb" );
#endif // WIN32

    if ( !infile ) {
#ifdef _DEBUG
        std::cerr << "Unable to open file '" << filename << "'" << std::endl;
#endif /* DEBUG */
        return NULL;
    }

    fseek( infile, 0, SEEK_END );
    int len = ftell( infile );
    fseek( infile, 0, SEEK_SET );

    GLchar* source = new GLchar[len+1];

    fread( source, 1, len, infile );
    fclose( infile );

    source[len] = 0;

    return const_cast<const GLchar*>(source);
}
Example #30
0
void load_key() 
{
    FILE *data_file = NULL;
    data_file = fopen("data","r");
    if (data_file) {
        fseek(data_file, 0, SEEK_END);
        int size = ftell(data_file);
        fseek(data_file, 0, SEEK_SET);
        uint8_t data[size];
        if (fread(data, sizeof(uint8_t), size, data_file) != size) {
            printf("\n[i] Could not read the data file. Exiting.");
            exit(1);
        }

        Messenger_load(data, size);
    } else {
        int size = Messenger_size();
        uint8_t data[size];
        Messenger_save(data);
        data_file = fopen("data", "w");

        if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
            printf("\n[i] Could not write data to file. Exiting.");
            exit(1);
        }
    }
    fclose(data_file);
}