コード例 #1
0
static int create_image_layout(const char* kernelfile, const char* rootfsfile, image_info_t* im)
{
	part_data_t* kernel = &im->parts[0];
	part_data_t* rootfs = &im->parts[1];

	strcpy(kernel->partition_name, "kernel");
	kernel->partition_index = 1;
	kernel->partition_baseaddr = partition_startaddr;
	if ( (kernel->partition_length = filelength(kernelfile)) < 0) return (-1);
	kernel->partition_memaddr = 0x80041000;
	kernel->partition_entryaddr = 0x80041000;
	strncpy(kernel->filename, kernelfile, sizeof(kernel->filename));

	if (filelength(rootfsfile) + kernel->partition_length > FIRMWARE_MAX_LENGTH)
		return (-2);

	strcpy(rootfs->partition_name, "rootfs");
	rootfs->partition_index = 2;
	rootfs->partition_baseaddr = partition_startaddr + kernel->partition_length;
	rootfs->partition_length = FIRMWARE_MAX_LENGTH - kernel->partition_length;
	rootfs->partition_memaddr = 0x00000000;
	rootfs->partition_entryaddr = 0x00000000;
	strncpy(rootfs->filename, rootfsfile, sizeof(rootfs->filename));

	im->part_count = 2;

	return 0;
}
コード例 #2
0
ファイル: data_ovl.cpp プロジェクト: kindy/synchronet-bbs-1
extern "C" BOOL DLLCALL putmsgptrs(scfg_t* cfg, uint usernumber, subscan_t* subscan)
{
	char		str[256];
	ushort		idx;
	uint16_t	scancfg;
	uint		i,j;
	int 		file;
	ulong		length;
	uint32_t	l=0L;

	if(!usernumber)
		return(FALSE);
	sprintf(str,"%suser/ptrs/%4.4u.ixb", cfg->data_dir,usernumber);
	if((file=nopen(str,O_WRONLY|O_CREAT))==-1) {
		return(FALSE); 
	}
	length=(ulong)filelength(file);
	for(i=0;i<cfg->total_subs;i++) {
		if(subscan[i].sav_ptr==subscan[i].ptr 
			&& subscan[i].sav_last==subscan[i].last
			&& length>=((cfg->sub[i]->ptridx+1)*10UL)
			&& subscan[i].sav_cfg==subscan[i].cfg)
			continue;
		while(filelength(file)<(long)(cfg->sub[i]->ptridx)*10) {
			lseek(file,0L,SEEK_END);
			idx=(ushort)(tell(file)/10);
			for(j=0;j<cfg->total_subs;j++)
				if(cfg->sub[j]->ptridx==idx)
					break;
			write(file,&l,sizeof(l));
			write(file,&l,sizeof(l));
			scancfg=0xff;					
			if(j<cfg->total_subs) {
				if(!(cfg->sub[j]->misc&SUB_NSDEF))
					scancfg&=~SUB_CFG_NSCAN;
				if(!(cfg->sub[j]->misc&SUB_SSDEF))
					scancfg&=~SUB_CFG_SSCAN; 
			} else	/* default to scan OFF for unknown sub */
				scancfg&=~(SUB_CFG_NSCAN|SUB_CFG_SSCAN);
			write(file,&scancfg,sizeof(scancfg)); 
		}
		lseek(file,(long)((long)(cfg->sub[i]->ptridx)*10),SEEK_SET);
		write(file,&(subscan[i].ptr),sizeof(subscan[i].ptr));
		write(file,&(subscan[i].last),sizeof(subscan[i].last));
		write(file,&(subscan[i].cfg),sizeof(subscan[i].cfg));
	}
	close(file);
	if(!flength(str))				/* Don't leave 0 byte files */
		remove(str);

	return(TRUE);
}
コード例 #3
0
ファイル: LForthMachine.cpp プロジェクト: loguntsov/forth-emu
bool LFMRunFile(AnsiString File)
{
FILE *fl;
if ((fl=fopen(File.c_str(),"r"))!=NULL)
            {
            int h=open(File.c_str(),O_RDONLY);
            char *buf=new char[filelength(h)];
            fread(buf,filelength(h),filelength(h),fl);
            fclose(fl);close(h);
            LFMRunString(buf);
            delete buf;
            return true;
            } else return false;
}
コード例 #4
0
int WRLoadBitmapFile( WRInfo *info )
{
    int                 ok;
    int                 file_handle;
    long int            file_length;
    char                fn[_MAX_FNAME];
    WResID              *type;
    WResID              *name;
    WResLangType        def_lang;

    file_handle         = -1;
    def_lang.sublang    = DEF_LANG;
    def_lang.lang       = DEF_SUBLANG;

    ok = ( info != NULL );

    if( ok ) {
        ok = ( ( file_handle = ResOpenFileRO( info->file_name ) ) != -1 );
    }

    if( ok ) {
        file_length = filelength( file_handle );
        ok = ( ( file_length != 0 ) && ( file_length != -1 ) );
    }

    if( ok ) {
        type = WResIDFromNum( (long)RT_BITMAP );
        ok = ( type != NULL );
    }

    if( ok ) {
        _splitpath( info->file_name, NULL, NULL, fn, NULL );
        name = WResIDFromStr( fn );
        ok = ( name != NULL );
    }

    if( ok ) {
        ok = ( ( info->dir = WResInitDir() ) != NULL );
    }

    if( ok ) {
        ok = !WResAddResource( type, name, 0, sizeof(BITMAPFILEHEADER),
                               file_length - sizeof(BITMAPFILEHEADER),
                               info->dir, &def_lang, NULL );
    }

    if( file_handle != -1 ) {
        ResCloseFile( file_handle );
    }

    if( name ) {
        WRMemFree( name );
    }

    if( type ) {
        WRMemFree( type );
    }

    return( ok );
}
コード例 #5
0
ファイル: sys_sun.c プロジェクト: ACIIL/Quake
int Sys_FileOpenRead (char *path, int *hndl)
{
    FILE    *f;
    int             i;
    
    i = findhandle ();
    
    f = fopen(path, "rb");
    if (!f)
    {
	*hndl = -1;
	return -1;
    }
    sys_handles[i].hFile = f;
    sys_handles[i].nLen = filelength(f);
    sys_handles[i].nPos = 0;
    sys_handles[i].pMap = mmap( 0, sys_handles[i].nLen, PROT_READ, MAP_SHARED, fileno( sys_handles[i].hFile ), 0 );
    if (!sys_handles[i].pMap || (sys_handles[i].pMap == (char *)-1))
    {
	printf( "mmap %s failed!", path );
	sys_handles[i].pMap = NULL;
    }

    *hndl = i;
    
    return( sys_handles[i].nLen );
}
コード例 #6
0
ファイル: audio.c プロジェクト: TimofonicJunkRoom/Oldies
int main (int argc, char **argv) {
  int file;
  mpeg_header header;

  printf ("RBMP2\n\n");

  file=open (argv[1],O_BINARY|O_RDONLY);
  len=filelength (file);
  buffer=p=(byte *) malloc (len);
  read (file,buffer,len);
  close (file);

  read_header (&header);

  if (header.magic!=0x1FFF) {
    printf ("Not a valid MP2 file\n");
    exit (1);
  }

  printf ("MPEG Audio Layer %d\n",header.layer);
  printf ("Bitrate: %d\n",header.bitrate);
  printf ("Sample rate: %d\n",header.sample_rate);
  printf ("Stereo mode: %s\n",mpeg_stereo_mode[header.stereo_mode]);
  printf ("Padding bit: %d\n",header.padding_bit);
  printf ("Protection bit: %d\n",header.protection_bit);
  printf ("Frame size: %d\n",header.frame_size);

  read_frame (&header);

  return 0;
}
コード例 #7
0
int CMistfall::LoadFile(char* fname)
{
  FILE* f = fopen(fname, "rb");
  if (f == NULL) return MF_ERR_CANTOPENFILE;

  i_phys_len = filelength(fileno(f));
  if ( (i_phys_len < MF_PHYSFILE_MIN_SIZE) ||
       (i_phys_len > MF_PHYSFILE_MAX_SIZE) )
  {
    fclose(f);
    return MF_ERR_BADFILESIZE;
  }

  i_phys_mem = (BYTE*)ZReAlloc( i_phys_mem, i_phys_len+1 );
  if (i_phys_mem == NULL)
  {
    fclose(f);
    return MF_ERR_NOMEMORY;
  }

  fread(i_phys_mem, 1, i_phys_len, f);

  fclose(f);

  return MF_ERR_SUCCESS;
} // CMistfall::LoadFile()
コード例 #8
0
//DOC!!
BOOL ef_LoadBinaryFile( const char  pc_FILENM[], 
						void *const  pv, 
						const int  i_LEN)	{
	FILE * pfl;
	char * pc = NULL;
	BOOL  f_failure;

	if (!( pc_FILENM && pv && i_LEN))
		return FALSE;

	if (!( pfl = fopen( pc_FILENM, "rb")))
		return FALSE;

	if (f_failure = filelength( fileno( pfl)) < i_LEN)
		goto errJump;

	fread( pv, 1, i_LEN, pfl);
	f_failure = ferror( pfl);

errJump:
	if (fclose( pfl) == EOF)
		if (!f_failure)
			f_failure = TRUE;

	return !f_failure;
} //ef_LoadBinaryFile(
コード例 #9
0
//
// compress() is the public function used to compress
// a single file.  It has to take care of opening the
// input and output files and setting up the buffers for
// Zlib.  It then calls deflate() repeatedly until all
// input and output processing has been done, and finally
// closes the files and cleans up the Zlib structures.
//
void CStdCompress::CompressFile( const char *input,
                                 const char *output,
                                 int level )
{

try
{
    err = Z_OK;
    avail_in = 0;
    avail_out = output_length;
    next_out = output_buffer;
    m_AbortFlag = 0;

    fin  = fopen( input, "rb" );
    fout = fopen( output, "wb" );
    length = filelength( fileno( fin ) );
    deflateInit( this, level );
    for ( ; ; ) {
        if ( m_AbortFlag )
            break;
        if ( !load_input() )
            break;
        err = deflate( this, Z_NO_FLUSH );
        flush_output();
        if ( err != Z_OK )
            break;
        progress( percent() );
    }
    for ( ; ; ) {
        if ( m_AbortFlag )
            break;
        err = deflate( this, Z_FINISH );
        if ( !flush_output() )
            break;
        if ( err != Z_OK )
            break;
    }
    progress( percent() );
    deflateEnd( this );
    if ( m_AbortFlag )
        status( "User Abort" );
    else if ( err != Z_OK && err != Z_STREAM_END )
        status( "Zlib Error" );
    else {
        status( "Success" );
        err = Z_OK;
    }
    fclose( fin );
    fclose( fout );
    fin = 0;
    fout = 0;

	if(err != Z_OK && !m_AbortFlag)
		THROW_ERROR(Std_Err_ZLIB_lCompress, Std_Err_ZLIB_strCompress);
}
catch(CStdErrorInfo oError)
{RELAY_ERROR(oError);}
catch(...)
{THROW_ERROR(Std_Err_ZLIB_lUnspecifiedError, Std_Err_ZLIB_strUnspecifiedError);}
}
コード例 #10
0
ファイル: cfgfile.cpp プロジェクト: tenk-a/misc
/** ファイル一括読み込み(ロード)
 *  @param  name    読みこむファイル
 *  @param  buf     読みこむメモリ。NULLが指定されれば mallocし、16バイト余分に確保する
 *  @param  bufsz   bufのサイズ。0が指定されれば ファイルサイズとなる
 *  @param  rdszp   NULLでなければ、読みこんだファイルサイズを入れて返す
 *  @return 	    bufのアドレスかmallocされたアドレス. エラー時はNULLを返す
 */
static void *file_loadAbs(const char *name, void *buf, int bufsz, int *rdszp)
{
    FILE *fp;
    int  l;

    fp = fopen(name, "rb");
    if (fp == NULL)
    	return NULL;
    l = filelength(fileno(fp));
    if (rdszp)
    	*rdszp = l;
    if (bufsz == 0)
    	bufsz = l;
    if (l > bufsz)
    	l = bufsz;
    if (buf == NULL) {
    	bufsz = (bufsz + 15 + 16) & ~15;
    	buf = calloc(1, bufsz);
    	if (buf == NULL)
    	    return NULL;
    }
    fread(buf, 1, l, fp);
    if (ferror(fp)) {
    	fclose(fp);
    	buf = NULL;
    }
    fclose(fp);
    return buf;
}
コード例 #11
0
ファイル: str.cpp プロジェクト: ftnapps/pkg-sbbs
void sbbs_t::read_sif_dat(char *siffile, char *datfile)
{
	char *buf;
	int file;
	long length;

	if((file=nopen(datfile,O_RDONLY))==-1) {
		errormsg(WHERE,ERR_OPEN,datfile,O_RDONLY);
		return; 
	}
	length=filelength(file);
	if(!length) {
		close(file);
		return; 
	}
	if((buf=(char *)malloc(length))==NULL) {
		close(file);
		errormsg(WHERE,ERR_ALLOC,datfile,length);
		return; 
	}
	read(file,buf,length);
	close(file);
	sof(siffile,buf,length);
	free(buf);
}
コード例 #12
0
ファイル: bplus.c プロジェクト: edisenwang/libmm
static RECPOS get_free()
{
    RECPOS  r, rt;

    r = pci->dx.ff;
    if ( r != NULLREC )
    {  
        if( read_if(r, (char *)&rt, sizeof( RECPOS )))
        {
            pci->dx.ff = rt;
        }
        else 
        {
            DD("error in file %s line %d:\n", __FILE__, __LINE__);
            getchar();
            exit(0);
        }
    }
    else
    {
        r = filelength (pci->ixfile);
    }

    return r;
} 
コード例 #13
0
ファイル: sbj.c プロジェクト: ftnapps/pkg-sbbs
void getnodemsg()
{
	char str[81], *buf;
	int file;
	ulong length;

nodesync();
sprintf(str,"message.%d",node_num);
if(flength(str)<1L) 					/* v1.02 fix */
	return;
if((file=nopen(str,O_RDWR))==-1) {
	bprintf("Couldn't open %s\r\n",str);
	return; }
length=filelength(file);
if((buf=malloc(length+1L))==NULL) {
	close(file);
	bprintf("\7\r\ngetnodemsg: Error allocating %lu bytes of memory for %\r\n"
		,length+1L,str);
	return; }
buf[read(file,buf,length)]=0;
chsize(file,0);
close(file);
if(!symbols)
	strip_symbols(buf);
bputs(buf);
free(buf);
}
コード例 #14
0
ファイル: NodeFormUnit.cpp プロジェクト: K6BSD/SBBSUnstable
char* username(int usernumber,char *strin)
{
    char str[256];
    char c;
    int file;

    if(usernumber<1) {
        strcpy(strin,"UNKNOWN USER");
        return(strin);
    }
    sprintf(str,"%suser/name.dat",MainForm->cfg.data_dir);
    if((file=_sopen(str,O_RDONLY,SH_DENYWR,S_IWRITE))==-1) {
        return("<!ERROR opening name.dat>");
    }
    if(filelength(file)<(long)((long)usernumber*(LEN_ALIAS+2))) {
        close(file);
        strcpy(strin,"UNKNOWN USER");
        return(strin);
    }
    lseek(file,(long)((long)(usernumber-1)*(LEN_ALIAS+2)),SEEK_SET);
    read(file,strin,LEN_ALIAS);
    close(file);
    for(c=0;c<LEN_ALIAS;c++)
        if(strin[c]==ETX) break;
    strin[c]=0;
    if(!c)
        strcpy(strin,"DELETED USER");
    return(strin);
}
コード例 #15
0
ファイル: fname.cpp プロジェクト: DavidKinder/Level9
long FName::GetFileSize()
{
    int hand=open(Str,O_RDONLY);
    long len=filelength(hand);
    close(hand);
    return len;
}
コード例 #16
0
HTTPRESULT *http_read(char *url)
{
	HTTPRESULT *result = http_new_result();
	
	if ( strncmp(url,"http://",7)==0 )
	{
		output_warning("http_read('%s'): http access not implemented", url);
	}

	else if ( strncmp(url,"file://",7)==0 )
	{
		FILE *fp = fopen(url+7,"rt");
		if ( fp==NULL )
		{
			output_error("http_read('%s'): unable to access file", url);
		}
		else
		{
			result->body.size = filelength(fileno(fp))+1;
			result->body.data = malloc(result->body.size);
			memset(result->body.data,0,result->body.size);
			if ( fread(result->body.data,1,result->body.size,fp)<=0 )
			{
				output_error("http_read('%s'): unable to read file", url);
				result->status = errno;
			}
			else
				result->status = 0;
		}
	}
	return result;
}
コード例 #17
0
ファイル: FILE.C プロジェクト: LesInk/Test
T_word32 FileGetSize(T_byte8 *p_filename)
{
    T_word32 size ;
#if defined(WIN32)
    FILE *fp;

    DebugRoutine("FileGetSize");
    fp = fopen(p_filename, "rb");
    size = filelength(fileno(fp));
    fclose(fp);
    DebugEnd() ;
#else
    struct find_t fileinfo ;

    DebugRoutine("FileGetSize") ;

    /* Get information about the file. */
    if (_dos_findfirst(p_filename, _A_NORMAL, &fileinfo) == 0)  {
        /* If we found the file, return the file size. */
        size = fileinfo.size ;
    } else {
        /* If we didn't find the file, return a zero. */
        size = 0 ;
    }

    DebugEnd() ;
#endif

    return size ;
}
コード例 #18
0
static void openFiles( void )
{
    int objhdl;

    objhdl = open( ObjFileName, O_RDONLY | O_BINARY );
    if( objhdl != -1 ) {
        if( ListFileName != NULL ) {
            OutputDest = open( ListFileName, O_WRONLY | O_CREAT | O_TRUNC, PMODE_RW );
            if( OutputDest == -1 )
                openError( ListFileName );
            ChangePrintDest( OutputDest );
        }
        objFileLen = filelength( objhdl );
        if( objFileLen == 0 ) {
            LeaveProgram( RC_OKAY, WHERE_OBJ_ZERO_LEN );
        }
        objFileBuf = MemAlloc( objFileLen );
        objFilePos = 0;
        if( posix_read( objhdl, objFileBuf, objFileLen ) == -1 ) {
            openError( ObjFileName );
        }
        close( objhdl );
    } else {
        openError( ObjFileName );
    }
}
コード例 #19
0
ファイル: MAPMAKE.C プロジェクト: cxong/MagusPreservation
int ReadScreen( void )
{
  char name[FNSIZE], directory[FMSIZE];
  short button;
  int f, status;
  	  
  status = 0;
  getcd( 0, directory);
  strcat( directory, "\\*.NEO");
  *name = 0;
  fsel_exinput( directory, name, &button, "L„s NEO-sk„rm");
  if (button == 1)
  {
  	*(strrchr( directory, '\\')+1) = 0;
    strcat( directory, name);
    f = open( directory, O_RDONLY | O_RAW, 0);
    if (f >= 0)
    {
      if (filelength( f) == 32128)
      {
        read( f, Physbase(), 128);
        read( f, Physbase(), 32000);
        status = 1;
      }
      else
        form_alert( 1, "[3][Ej NeoChrome fil][Ok]");
      close( f);
    }
    else
      form_alert( 1, "[3][Filen finns inte][Ok]");
  }
  return status;
}
コード例 #20
0
static char *ReadIndirectFile( void )
/***********************************/
{
    char        *env;
    char        *str;
    int         handle;
    int         len;
    char        ch;

    env = NULL;
    handle = open( ParamBuf, O_RDONLY | O_BINARY );
    if( handle != -1 ) {
        len = filelength( handle );
        env = AsmAlloc( len + 1 );
        read( handle, env, len );
        env[len] = '\0';
        close( handle );
        // zip through characters changing \r, \n etc into ' '
        str = env;
        while( *str ) {
            ch = *str;
            if( ch == '\r' || ch == '\n' ) {
                *str = ' ';
            }
#if !defined(__UNIX__)
            if( ch == 0x1A ) {      // if end of file
                *str = '\0';        // - mark end of str
                break;
            }
#endif
            ++str;
        }
    }
    return( env );
}
コード例 #21
0
ファイル: FIGURA.CPP プロジェクト: felipelalli/micaroni
void obj_figura::abre_arquivo(char* vnomearq)
{
  if (!carquivo_definido)
  {
    if (!(carquivo = fopen(vnomearq, "rb")))
    {
      carquivo = fopen(vnomearq, "ab+");
      carquivo_somente_leitura = FALSO;
    }
    else
    {
      cnumero_de_nos = (unsigned int) filelength(fileno(carquivo)) / sizeof(estrutura_circular);
      carquivo_somente_leitura = VERDADEIRO;
    }

    strcpy(cnomearq, vnomearq);

    carquivo_definido = VERDADEIRO;
    rewind(carquivo);
  }
  else
   {
     fecha_arquivo();
     abre_arquivo(vnomearq);
   }
}
コード例 #22
0
ファイル: bspinfo.c プロジェクト: JoelTroch/am_src_30jan2011
void main (int argc, char **argv)
{
	int			i;
	char		source[1024];
	int			size;
	FILE		*f;

	printf( "bspinfo.exe v2.1 (%s)\n", __DATE__ );
	printf ("---- bspinfo ----\n" );


	if (argc == 1)
		Error ("usage: bspinfo bspfile [bspfiles]");
		
	for (i=1 ; i<argc ; i++)
	{
		printf ("---------------------\n");
		strcpy (source, argv[i]);
		DefaultExtension (source, ".bsp");
		f = fopen (source, "rb");
		if (f)
		{
			size = filelength (f);
			fclose (f);
		}
		else
			size = 0;
		printf ("%s: %i\n", source, size);
		
		LoadBSPFile (source);		
		PrintBSPFileSizes ();
		printf ("---------------------\n");
	}
}
コード例 #23
0
ファイル: 4-23.c プロジェクト: Huericiz/C_lg_small_examples
main()
{
  FILE*fp,*stream;
  char *c="Hello the world";
  int handle;
  long file_length;
  if((fp=fopen("Extemp.txt","w+"))!=NULL)
  {
    fputs("\nYou are welcome",fp);
    fputc(':',fp);
    fprintf(fp,"\n%s",c);
    fclose(fp);
  }
  if((stream=fopen("Extemp.txt","r"))!=NULL)
  {
    handle=fileno(stream);
    file_length=filelength(handle);
    printf("\nThe filelength is %ld",file_length);
  }
  else
  {
    printf("\nCan't open the file!");
  }
  getch();
}
コード例 #24
0
ファイル: QFILES.C プロジェクト: ChunHungLiu/Quake-Tools
/*
===========
PackFile

Copy a file into the pak file
===========
*/
void PackFile (char *src, char *name)
{
	FILE	*in;
	int		remaining, count;
	char	buf[4096];
	
	if ( (byte *)pf - (byte *)pfiles > sizeof(pfiles) )
		Error ("Too many files in pak file");
	
	in = SafeOpenRead (src);
	remaining = filelength (in);

	pf->filepos = LittleLong (ftell (packhandle));
	pf->filelen = LittleLong (remaining);
	strcpy (pf->name, name);
	printf ("%64s : %7i\n", pf->name, remaining);

	packbytes += remaining;
	
	while (remaining)
	{
		if (remaining < sizeof(buf))
			count = remaining;
		else
			count = sizeof(buf);
		SafeRead (in, buf, count);
		SafeWrite (packhandle, buf, count);
		remaining -= count;
	}

	fclose (in);
	pf++;
}
コード例 #25
0
bool SprConverter::LoadSprFile( const char* pszFileName )
{
	Release();
	if(pszFileName == NULL)
		return false;

	FILE* pF = NULL;
	pF = fopen(pszFileName, "rb");
	if (pF == NULL)
		return false;

	m_uSprDataSize = filelength(fileno(pF));
	m_pSprData = new BYTE[m_uSprDataSize];
	if (m_pSprData == NULL)
	{
		fclose(pF);
		return false;
	}
	if (fread(m_pSprData, m_uSprDataSize, 1, pF) == 1)
	{
		fclose(pF);
		m_pSprHead = (FSprHead*)m_pSprData;
		if ((LPBYTE)m_pSprHead + sizeof(FSprHead) > (LPBYTE)m_pSprData + m_uSprDataSize)
		{
			return false;
		}
		if (*(int*)&m_pSprHead->Comment[0] != SPR_COMMENT_FLAG || m_pSprHead->Colors > 256 || !m_pSprHead->Frames || m_pSprHead->FrameFormat != enumFF_Default)
		{
			return false;
		}
		m_pSprPaList = (FSprPal*)((LPBYTE)m_pSprHead + sizeof(FSprHead));
		if ((LPBYTE)m_pSprPaList + sizeof(FSprPal) * m_pSprHead->Colors > (LPBYTE)m_pSprData + m_uSprDataSize)
		{
			return false;
		}
		m_pSprOffsList = (FSprOffs*)((LPBYTE)m_pSprPaList + sizeof(FSprPal) * m_pSprHead->Colors);
		if ((LPBYTE)m_pSprOffsList + sizeof(FSprOffs) * m_pSprHead->Frames > (LPBYTE)m_pSprData + m_uSprDataSize)
		{
			return false;
		}
		m_ppSprFrameList = new FSprFrame*[m_pSprHead->Frames];
		if (m_ppSprFrameList == NULL)
		{
			return false;
		}
		LPBYTE pSprite = (LPBYTE)m_pSprOffsList + sizeof(FSprOffs) * m_pSprHead->Frames;
		for (int i = 0; i < m_pSprHead->Frames; i++)
		{
			m_ppSprFrameList[i] = (FSprFrame*)(pSprite + m_pSprOffsList[i].Offset);
			//检查长度是否溢出
			//To do...
		}
	}
	else
	{
		fclose(pF);
		return false;
	}
	return true;
}
コード例 #26
0
ファイル: smdskcpy.c プロジェクト: FDOS/diskcopy
CROSSCUT_NLS_DATA_IMPORT

int
ReadFileIntoMemory (char *file, char *buffer, unsigned bsize)
{
  int handle;
  unsigned long fsize, i;

  handle = open (file, O_RDONLY | O_BINARY);
  if (handle == -1)
    return FALSE;

  fsize = filelength (handle);
  if ((fsize % bsize) != 0)
    {
      close (handle);
      return FALSE;
    }

  for (i = 0; i < fsize / bsize; i++)
    {
      if ((read (handle, buffer, bsize) != bsize) ||
	  (!WriteMemoryBlock (buffer, bsize)))
	{
	  close (handle);
	  return FALSE;
	}
    }


  close (handle);
  return TRUE;
}
コード例 #27
0
ファイル: L16-1.C プロジェクト: CHMyFork/GPBB
int main(int argc, char **argv) {
   int Handle;
   unsigned int BlockSize;
   long FileSize;
   unsigned long WordCount = 0;
   char *Buffer, CharFlag = 0, PredCharFlag, *BufferPtr, Ch;

   if (argc != 2) {
      printf("usage: wc <filename>\n");
      exit(1);
   }

   if ((Buffer = malloc(BUFFER_SIZE)) == NULL) {
      printf("Can't allocate adequate memory\n");
      exit(1);
   }

   if ((Handle = open(argv[1], O_RDONLY | O_BINARY)) == -1) {
      printf("Can't open file %s\n", argv[1]);
      exit(1);
   }

   if ((FileSize = filelength(Handle)) == -1) {
      printf("Error sizing file %s\n", argv[1]);
      exit(1);
   }

   /* Process the file in chunks */
   while (FileSize > 0) {
      /* Get the next chunk */
      FileSize -= (BlockSize = min(FileSize, BUFFER_SIZE));
      if (read(Handle, Buffer, BlockSize) == -1) {
         printf("Error reading file %s\n", argv[1]);
         exit(1);
      }
      /* Count words in the chunk */
      BufferPtr = Buffer;
      do {
         PredCharFlag = CharFlag;
         Ch = *BufferPtr++ & 0x7F; /* strip high bit, which some
                                      word processors set as an
                                      internal flag */
         CharFlag = ((Ch >= 'a') && (Ch <= 'z')) ||
                    ((Ch >= 'A') && (Ch <= 'Z')) ||
                    ((Ch >= '0') && (Ch <= '9')) ||
                    (Ch == '\'');
         if ((!CharFlag) && PredCharFlag) {
            WordCount++;
         }
      } while (--BlockSize);
   }

   /* Catch the last word, if any */
   if (CharFlag) {
      WordCount++;
   }
   printf("\nTotal words in file: %lu\n", WordCount);
   return(0);
}
コード例 #28
0
int main(void)
{

void    *gothic_fontp;    /* points to font bufferin memory */
int      handle;          /* file handle used for I/O */
unsigned fsize;           /* size of file (andbuffer) */

int errorcode;
int graphdriver;
int graphmode;

/* open font file */
handle = open("LCOM.CHR", O_RDONLY|O_BINARY);
if (handle == -1)
{
printf("unable to open font file 'LCOM.CHR'\n");
exit(1);
}
/* find out size of the file */
fsize = filelength(handle);
/* allocate buffer */
gothic_fontp = malloc(fsize);
if (gothic_fontp == NULL)
{
printf("unable to allocate memory for font file'LCOM.CHR'\n");
exit(1);
}
/* read font into memory */
if (read(handle, gothic_fontp, fsize) != fsize)
{
printf("unable to read font file 'LCOM.CHR'\n");
exit(1);
}
/* close font file */
close(handle);
/* register font */
if (registerfarbgifont(gothic_fontp) != 8)     //
{
printf("unable to register font file 'LCOM.CHR'\n");
exit(1);
}
/* detect and initialize graphix */
graphdriver = DETECT;
initgraph(&graphdriver, &graphmode, "..");
errorcode = graphresult();
if (errorcode != grOk)
{
printf("graphics error:%s\n",grapherrormsg(errorcode));
exit(1);
}
settextstyle(8, HORIZ_DIR, 4);


   sscreen( );
   getch();
   closegraph();

   return 0;
}
コード例 #29
0
ファイル: filedat.c プロジェクト: K6BSD/SBBSUnstable
BOOL DLLCALL removefiledat(scfg_t* cfg, file_t* f)
{
	char	c,str[MAX_PATH+1],ixbname[12],*ixbbuf,fname[13];
    int		i,file;
	long	l,length;

	SAFECOPY(fname,f->name);
	for(i=8;i<12;i++)   /* Turn FILENAME.EXT into FILENAMEEXT */
		fname[i]=fname[i+1];
	SAFEPRINTF2(str,"%s%s.ixb",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
	if((file=sopen(str,O_RDONLY|O_BINARY,SH_DENYWR))==-1) {
		return(FALSE); 
	}
	length=(long)filelength(file);
	if(!length) {
		close(file);
		return(FALSE); 
	}
	if((ixbbuf=(char *)malloc(length))==0) {
		close(file);
		return(FALSE); 
	}
	if(lread(file,ixbbuf,length)!=length) {
		close(file);
		free((char *)ixbbuf);
		return(FALSE); 
	}
	close(file);
	if((file=sopen(str,O_WRONLY|O_TRUNC|O_BINARY,SH_DENYRW))==-1) {
		return(FALSE); 
	}
	for(l=0;l<length;l+=F_IXBSIZE) {
		for(i=0;i<11;i++)
			ixbname[i]=ixbbuf[l+i];
		ixbname[i]=0;
		if(stricmp(ixbname,fname))
			if(lwrite(file,&ixbbuf[l],F_IXBSIZE)!=F_IXBSIZE) {
				close(file);
				free((char *)ixbbuf);
				return(FALSE); 
		} 
	}
	free((char *)ixbbuf);
	close(file);
	SAFEPRINTF2(str,"%s%s.dat",cfg->dir[f->dir]->data_dir,cfg->dir[f->dir]->code);
	if((file=sopen(str,O_WRONLY|O_BINARY,SH_DENYRW))==-1) {
		return(FALSE); 
	}
	lseek(file,f->datoffset,SEEK_SET);
	c=ETX;          /* If first char of record is ETX, record is unused */
	if(write(file,&c,1)!=1) { /* So write a D_T on the first byte of the record */
		close(file);
		return(FALSE); 
	}
	close(file);
	if(f->dir==cfg->user_dir)  /* remove file from index */
		rmuserxfers(cfg,0,0,f->name);
	return(TRUE);
}
コード例 #30
0
ファイル: main.c プロジェクト: Ukusbobra/open-watcom-v2
int GetFileSize(char *name)
{
	int n,m;
	if( (n=open(name,O_RDONLY | O_BINARY)) == -1) return(0);
	m=filelength(n);
	close(n);
	return(m);
}