Exemplo n.º 1
0
static FILE *rom_findrom(const char *filename, rominfo_t *rominfo)
{
   FILE *fp;

   ASSERT(rominfo);

   if (NULL == filename)
      return NULL;

   /* Make a copy of the name so we can extend it */
///   osd_fullname(rominfo->filename, filename);

   fp = _fopen(rominfo->filename, "rb");
   if (NULL == fp)
   {
      /* Didn't find the file?  Maybe the .NES extension was omitted */
      if (NULL == strrchr(rominfo->filename, '.'))
         strncat(rominfo->filename, ".nes", PATH_MAX - strlen(rominfo->filename));

      /* this will either return NULL or a valid file pointer */
      fp = _fopen(rominfo->filename, "rb");
   }

   return fp;
}
CachedFileStream::CachedFileStream(CachedFileStream* cfs, int startpos,
	int size, bool autoFree)
{
	this->size = size;
	this->startpos = startpos;
	this->autoFree = autoFree;
	char cpath[_MAX_PATH];
	PathJoin( cpath, core->CachePath, cfs->filename, NULL );
	str = _fopen( cpath, "rb" );
	if (str == NULL) {
		str = _fopen( cfs->originalfile, "rb" );
		if (str == NULL) {
			printf( "Can't open stream (maybe leaking?)\n" );
			return;
		}
		strncpy( originalfile, cfs->originalfile, sizeof(originalfile) );
		strncpy( filename, cfs->filename, sizeof(filename) );
	} else {
		strncpy( originalfile, cpath, sizeof(originalfile) );
		strncpy( filename, cfs->filename, sizeof(filename) );
	}
#ifdef _DEBUG
	core->CachedFileStreamPtrCount++;
#endif
	_fseek( str, startpos, SEEK_SET );
	
	
	Pos = 0;
}
CachedFileStream::CachedFileStream(const char* stream, bool autoFree)
{
	ExtractFileFromPath( filename, stream );
	PathJoin( originalfile, core->CachePath, filename, NULL );

	str = _fopen( originalfile, "rb" );
	if (str == NULL) {    // File was not found in cache
		if (core->GameOnCD) {
			_FILE* src = _fopen( stream, "rb" );
#ifdef _DEBUG
			core->CachedFileStreamPtrCount++;
#endif
			_FILE* dest = _fopen( originalfile, "wb" );
#ifdef _DEBUG
			core->CachedFileStreamPtrCount++;
#endif
			void* buff = malloc( 1024 * 1000 );
			do {
				size_t len = _fread( buff, 1, 1024 * 1000, src );
				size_t c = _fwrite( buff, 1, len, dest );
				if (c != len) {
					printf("CachedFileStream failed to write to cached file '%s' (from '%s')\n", originalfile, stream);
					abort();
				}
			} while (!_feof( src ));
			free( buff );
			_fclose( src );
#ifdef _DEBUG
			core->CachedFileStreamPtrCount--;
#endif
			_fclose( dest );
#ifdef _DEBUG
			core->CachedFileStreamPtrCount--;
#endif
		} else {  // Don't cache files already on hdd
			strncpy(originalfile, stream, _MAX_PATH);
		}
		str = _fopen( originalfile, "rb" );
	}
#ifdef _DEBUG
	core->CachedFileStreamPtrCount++;
#endif
	startpos = 0;
	_fseek( str, 0, SEEK_END ); 
	size = _ftell( str );
	_fseek( str, 0, SEEK_SET );
	Pos = 0;
	this->autoFree = autoFree;
}
Exemplo n.º 4
0
int get_number_line(const char* filename,void **p){
	FILE* fp;
	char* buffer;
	struct stat st;
	int num=0;
	int i;
	__stat _stat;
	__fread _fread;
	__fopen _fopen;
	__malloc _malloc;
	__fclose _fclose;
	const char* fmode;
	
	_stat=(__stat)p[0];
	_fopen=(__fopen)p[1];
	_malloc=(__malloc)p[2];
	_fread=(__fread)p[3];
	_fclose=(__fclose)p[4];
	fmode=(const char*)p[5];

	fp=_fopen(filename,fmode);
	if(fp==NULL) return -1;
	_stat(filename,&st);
	buffer=_malloc(st.st_size);
	if(buffer==NULL) return -1;
	_fread(buffer,st.st_size,1,fp);
	for(i=0;i<st.st_size;i++){
		if(buffer[i]=='\n') num++;
	}
	_fclose(fp);
	return num;
}
Exemplo n.º 5
0
	static bool CreateFile( String path ){
		if( FILE *f=_fopen( OS_STR( path ),OS_STR( "wb" ) ) ){
			fclose( f );
			return true;
		}
		return false;
	}
Exemplo n.º 6
0
int LoadConfigData(const wchar_t *path,const wchar_t *fname)
{
  int f;
  char *buf;
  int result=-1;
  void *cfg;
  FSTAT _fstat;
  unsigned int rlen;

  cfg=(char *)__segment_begin("CONFIG_C");

  unsigned int len=(char *)__segment_end("CONFIG_C")-(char *)__segment_begin("CONFIG_C");

  if ((buf=new char[len]))
  {
    if (fstat(path,fname,&_fstat)!=-1)
    {
      if ((f=_fopen(path,fname,0x001,0x180,0))>=0)
      {
        rlen=fread(f,buf,len);
        fclose(f);
        if (rlen!=_fstat.fsize || rlen!=len)  goto L_SAVENEWCFG;
        memcpy(cfg,buf,len);
        result=0;
      }
    }
    else
    {
    L_SAVENEWCFG:
      if ((f=_fopen(path,fname,0x204,0x180,0))>=0)
      {
        if (fwrite(f,cfg,len)==len) result=0;
        fclose(f);
      }
    }
    delete buf;
  }
  if (result>=0)
  {
    successed_config_path=path;
    successed_config_name=fname;
  }
  return(result);
}
Exemplo n.º 7
0
Arquivo: parse.c Projeto: ah42/cuda-p1
int file_exists(char* name) {
	if (name && name[0]) { /* Check for null string */
		FILE* stream;
		if ((stream = _fopen(name, "r"))) {
			fclose(stream);
			return 1;
		} else
			return 0;
	} else
		return 0;
}
Exemplo n.º 8
0
	static bool CopyFile( String srcpath,String dstpath ){
	
#if _WIN32
		return CopyFileW( OS_STR(srcpath),OS_STR(dstpath),FALSE );
#elif __APPLE__
	
		// Would like to use COPY_ALL here, but it breaks trans on MacOS - produces weird 'pch out of date' error with copied projects.
		//
		// Ranlib strikes back!
		//
		return copyfile( OS_STR(srcpath),OS_STR(dstpath),0,COPYFILE_DATA )>=0;
#else
		int err=-1;
		if( FILE *srcp=_fopen( OS_STR( srcpath ),OS_STR( "rb" ) ) ){
			err=-2;
			if( FILE *dstp=_fopen( OS_STR( dstpath ),OS_STR( "wb" ) ) ){
				err=0;
				char buf[1024];
				while( int n=fread( buf,1,1024,srcp ) ){
					if( fwrite( buf,1,n,dstp )!=n ){
						err=-3;
						break;
					}
				}
				fclose( dstp );
			}else{
				printf( "FOPEN 'wb' for CopyFile(%s,%s) failed\n",C_STR(srcpath),C_STR(dstpath) );
				fflush( stdout );
			}
			fclose( srcp );
		}else{
			printf( "FOPEN 'rb' for CopyFile(%s,%s) failed\n",C_STR(srcpath),C_STR(dstpath) );
			fflush( stdout );
		}
		return err==0;
#endif
	}
Exemplo n.º 9
0
FILE* fopen(const char *pathname,const char *mode)
{   
    //printf("INTERCEPTED Fopen\n");

    clock_t start = clock();

    FILE * ret = _fopen(pathname,mode);

    clock_t end = clock();

    double called_time = (double)(start-program_start)/(double)(CLOCKS_PER_SEC);

    double exec_time = (double)(end-start)/(double)(CLOCKS_PER_SEC);

    fprintf(logFile,"%lf %lf fopen %s %s \n",called_time,exec_time,pathname,mode);

    return ret;
}
Exemplo n.º 10
0
static void wrap_init(void)
{
    

    // Set original stdio functions

    _fopen = dlsym(RTLD_NEXT,"fopen");
    _fclose = dlsym(RTLD_NEXT,"fclose");
    //_fprintf = dlsym(RTLD_NEXT,"fprintf");
    //_vfprintf = dlsym(RTLD_NEXT,"vfprintf");
    //_fscanf = dlsym(RTLD_NEXT,"fscanf");
    //_sscanf = dlsym(RTstreamLD_NEXT,"sscanf");
    _fgetc = dlsym(RTLD_NEXT,"fgetc");
    _fputc = dlsym(RTLD_NEXT,"fputc");
    _feof = dlsym(RTLD_NEXT,"feof");
    _fread = dlsym(RTLD_NEXT,"fread");
    _fwrite = dlsym(RTLD_NEXT,"fwrite");
    _fgets = dlsym(RTLD_NEXT,"fgets");
    _fputs = dlsym(RTLD_NEXT,"fputs");
    _fseek = dlsym(RTLD_NEXT,"fseek");
    //_freopen = dlsym(RTLD_NEXT,"freopen");
    _fgetpos = dlsym(RTLD_NEXT,"fgetpos");
    _fsetpos = dlsym(RTLD_NEXT,"fsetpos");
    _ftell = dlsym(RTLD_NEXT,"ftell");


    // Set original fcntl and unistd functions

    _open = dlsym(RTLD_NEXT,"open");
    //_open64 = dlsym(RTLD_NEXT,"open64");
    _close = dlsym(RTLD_NEXT,"close");
    _read = dlsym(RTLD_NEXT,"read");
    _write = dlsym(RTLD_NEXT,"write");
    _pread = dlsym(RTLD_NEXT,"pread");
    _pwrite = dlsym(RTLD_NEXT,"pwrite");
    //_creat = dlsym(RTLD_NEXT,"creat");

    printf("START\n");

    logFile = _fopen("logFile.txt","w");

    program_start = clock();            // Set global program clock

}
Exemplo n.º 11
0
Arquivo: parse.c Projeto: ah42/cuda-p1
int IniGetInt(const char *inifile, const char *name, int *value, int dflt) {
	FILE *in;
	char buf[MAX_LINE_LENGTH + 1];
	int found = 0;
	in = _fopen(inifile, "r");
	if (!in)
		goto error;
	while (fgets(buf, MAX_LINE_LENGTH, in) && !found) {
		if (!strncmp(buf, name, strlen(name)) && buf[strlen(name)] == '=') {
			if (sscanf(&(buf[strlen(name) + 1]), "%d", value) == 1)
				found = 1;
		}
	}
	fclose(in);
	if (found)
		return 1;
	error: *value = dflt;
	return 0;
}
Exemplo n.º 12
0
Arquivo: parse.c Projeto: ah42/cuda-p1
int IniGetStr(const char *inifile, const char *name, char *string, const char* dflt) {
	FILE *in;
	char buf[MAX_LINE_LENGTH + 1];
	int found = 0;
	in = _fopen(inifile, "r");
	if (!in)
		goto error;
	while (fgets(buf, MAX_LINE_LENGTH, in) && !found) {
		if (!strncmp(buf, name, strlen(name)) && buf[strlen(name)] == '=') {
			if (sscanf(&(buf[strlen(name) + 1]), "%131s", string) == 1)
				found = 1;  // CuLu's strs are 132 bytes
		}
	}
	fclose(in);
	if (found)
		return 1;
	error: strcopy(string, dflt, MAX_LINE_LENGTH);
	return 0;
}
Exemplo n.º 13
0
FILE* __fastcall__ freopen (const char* name, const char* mode, FILE* f)
{
    /* Check if the file is open, if so, close it */
    if ((f->f_flags & _FOPEN) == 0) {
	/* File is not open */
	_errno = EINVAL;		/* File not input */
	return 0;
    }

    /* Close the file. Don't bother setting the flag, it will get
     * overwritten by _fopen.
     */
    if (close (f->f_fd) < 0) {
	/* An error occured, _oserror is set */
	return 0;
    }

    /* Open the file and return the descriptor */
    return _fopen (name, mode, f);
}
Exemplo n.º 14
0
Arquivo: cat.c Projeto: taras-ko/c
main(int argc, char *argv[])
{
	_FILE *fp;
	void filecopy(_FILE *, _FILE *);
	char *prog = argv[0];

	if (argc == 1) /* no args stdin -> stdout */
		filecopy(_stdin, _stdout);
	else
		while (--argc > 0)
			if ((fp = _fopen(*++argv, "r")) == NULL) {
				fprintf(stderr, "%s: can't open %s\n", prog, *argv);
				exit(1);
			} else {
				filecopy(fp, _stdout);
				//fclose(fp);
			}
	if (_ferror(_stdout)) {
		fprintf(stderr, "%s: error writing stdout\n", prog);
		exit(2);
	}
	exit(0);
}
Exemplo n.º 15
0
void
write_JPEG_file (char * filename, int quality)
{
  /* This struct contains the JPEG compression parameters and pointers to
   * working space (which is allocated as needed by the JPEG library).
   * It is possible to have several such structures, representing multiple
   * compression/decompression processes, in existence at once.  We refer
   * to any one struct (and its associated working data) as a "JPEG object".
   */
  struct jpeg_compress_struct cinfo;
  /* This struct represents a JPEG error handler.  It is declared separately
   * because applications often want to supply a specialized error handler
   * (see the second half of this file for an example).  But here we just
   * take the easy way out and use the standard error handler, which will
   * print a message on stderr and call exit() if compression fails.
   * Note that this struct must live as long as the main JPEG parameter
   * struct, to avoid dangling-pointer problems.
   */
  struct jpeg_error_mgr jerr;
  /* More stuff */
  int  outfile;		/* target file */
  JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
  int row_stride;		/* physical row width in image buffer */

  /* Step 1: allocate and initialize JPEG compression object */

  /* We have to set up the error handler first, in case the initialization
   * step fails.  (Unlikely, but it could happen if you are out of memory.)
   * This routine fills in the contents of struct jerr, and returns jerr's
   * address which we place into the link field in cinfo.
   */
  cinfo.err = jpeg_std_error(&jerr);
  /* Now we can initialize the JPEG compression object. */
  jpeg_create_compress(&cinfo);

  /* Step 2: specify data destination (eg, a file) */
  /* Note: steps 2 and 3 can be done in either order. */

  /* Here we use the library-supplied code to send compressed data to a
   * stdio stream.  You can also write your own code to do something else.
   * VERY IMPORTANT: use "b" option to _fopen() if you are on a machine that
   * requires it in order to write binary files.
   */
  if ((outfile = _fopen(filename, "wb")) == NULL) {
    fprintf(stderr, "can't open %s\n", filename);
    exit(1);
  }
  jpeg_stdio_dest(&cinfo, outfile);

  /* Step 3: set parameters for compression */

  /* First we supply a description of the input image.
   * Four fields of the cinfo struct must be filled in:
   */
  cinfo.image_width = image_width; 	/* image width and height, in pixels */
  cinfo.image_height = image_height;
  cinfo.input_components = 3;		/* # of color components per pixel */
  cinfo.in_color_space = JCS_RGB; 	/* colorspace of input image */
  /* Now use the library's routine to set default compression parameters.
   * (You must set at least cinfo.in_color_space before calling this,
   * since the defaults depend on the source color space.)
   */
  jpeg_set_defaults(&cinfo);
  /* Now you can set any non-default parameters you wish to.
   * Here we just illustrate the use of quality (quantization table) scaling:
   */
  jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);

  /* Step 4: Start compressor */

  /* TRUE ensures that we will write a complete interchange-JPEG file.
   * Pass TRUE unless you are very sure of what you're doing.
   */
  jpeg_start_compress(&cinfo, TRUE);

  /* Step 5: while (scan lines remain to be written) */
  /*           jpeg_write_scanlines(...); */

  /* Here we use the library's state variable cinfo.next_scanline as the
   * loop counter, so that we don't have to keep track ourselves.
   * To keep things simple, we pass one scanline per call; you can pass
   * more if you wish, though.
   */
  row_stride = image_width * 3;	/* JSAMPLEs per row in image_buffer */

  while (cinfo.next_scanline < cinfo.image_height) {
    /* jpeg_write_scanlines expects an array of pointers to scanlines.
     * Here the array is only one element long, but you could pass
     * more than one scanline at a time if that's more convenient.
     */
    row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
    (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
  }

  /* Step 6: Finish compression */

  jpeg_finish_compress(&cinfo);
  /* After finish_compress, we can close the output file. */
  _fclose(outfile);

  /* Step 7: release JPEG compression object */

  /* This is an important step since it will release a good deal of memory. */
  jpeg_destroy_compress(&cinfo);

  /* And we're done! */
}
Exemplo n.º 16
0
Arquivo: parse.c Projeto: ah42/cuda-p1
/************************************************************************************************************
 * Function name : clear_assignment                                                                         *
 *   													    *
 *     INPUT  :	char *filename										    *
 *		int exponent									            *
 *     OUTPUT :                                        							    *
 *                                                                                                          *
 *     0 - OK												    *
 *     3 - clear_assignment    : cannot open file <filename>						    *
 *     4 - clear_assignment    : cannot open file "__worktodo__.tmp"					    *
 *     5 - clear_assignment    : assignment not found							    *
 *     6 - clear_assignment    : cannot rename temporary workfile to regular workfile			    *
 *                                                                                                          *
 ************************************************************************************************************/
enum ASSIGNMENT_ERRORS clear_assignment(char *filename, int exponent) {
	int found = 0;
	FILE *f_in, *f_out;
	LINE_BUFFER line;  // line buffer
	char *tail = NULL;	// points to tail material in line, if non-null
	enum PARSE_WARNINGS value;
	unsigned int line_to_drop = UINT_MAX;
	unsigned int current_line;
	struct ASSIGNMENT assignment;  // the found assignment....
	
	f_in = _fopen(filename, "r");
	if (NULL == f_in) {
		fprintf(stderr, "Can't open workfile %s\n\n", filename);
		return CANT_OPEN_WORKFILE;
	}
	
	f_out = _fopen("__worktodo__.tmp", "w");
	if (NULL == f_out) {
		fclose(f_in);
		fprintf(stderr, "Can't open tmp workfile\n\n");
		return CANT_OPEN_TEMPFILE;
	}
	
	current_line = 0;
	while (END_OF_FILE != (value = parse_worktodo_line(f_in, &assignment, &line, &tail))) {
		current_line++;
#ifdef EBUG
		printf("Current_line = %d\n", current_line);
#endif
		if (NO_WARNING == value) {
			if ((exponent == assignment.exponent))	// make final decision
			{
				if (line_to_drop > current_line)
					line_to_drop = current_line;
#ifdef EBUG
				printf("Made final decision. linetodrop = %d, current = %d\n", line_to_drop, current_line);
#endif
				break;
			} else {
				line_to_drop = current_line + 1;	// found different assignment, can drop no earlier than next line
			}
		} else if ((BLANK_LINE == value) && (UINT_MAX == line_to_drop))
			line_to_drop = current_line + 1;
	}
#ifdef EBUG
	printf("Broken the first while loop, linetodrop = %d\n", line_to_drop);
#endif
	
	errno = 0;
	if (fseek(f_in, 0L, SEEK_SET)) {
		fclose(f_in);
		f_in = _fopen(filename, "r");
		if (NULL == f_in) {
			fclose(f_out);
			fprintf(stderr, "Can't open workfile %s\n\n", filename);
			return CANT_OPEN_WORKFILE;
		}
	}
	
	found = 0;
	current_line = 0;
	while (END_OF_FILE != (value = parse_worktodo_line(f_in, &assignment, &line, &tail))) {
		current_line++;
		if ((NO_WARNING != value) || found) {
			if ((found) || (current_line < line_to_drop))
				fprintf(f_out, "%s\n", line);
		} else	// assignment on the line, so we may need to print it..
		{
			found = (exponent == assignment.exponent);
			if (!found) {
				fprintf(f_out, "%s\n", line);
			} else	// we have the assignment...
			{
				// Do nothing; we don't print this to the temp file, 'cause we're trying to delete it :)
			}
		}
	}  // while.....
	fclose(f_in);
	fclose(f_out);
	if (!found) {
		fprintf(stderr, "Assignment M%d completed but not found in workfile\n\n", exponent);
		return ASSIGNMENT_NOT_FOUND;
	}
	if (remove(filename) != 0) {
		fprintf(stderr, "Cannot remove old workfile\n\n");
		return CANT_RENAME;
	}
	if (rename("__worktodo__.tmp", filename) != 0) {
		fprintf(stderr, "Cannot move tmp workfile to regular workfile\n\n");
		return CANT_RENAME;
	}
	return OK;
}
Exemplo n.º 17
0
Arquivo: parse.c Projeto: ah42/cuda-p1
/************************************************************************************************************
 * Function name : get_next_assignment                                                                      *
 *   													    *
 *     INPUT  :	char *filename										    *
 *		int *exponent										    *
 *		int* fft_length									    	    *
 *		char *hex_key[132];								    	    *
 *     OUTPUT :                                        							    *
 *                                                                                                          *
 *     0 - OK												    *
 *     1 - get_next_assignment : cannot open file							    *
 *     2 - get_next_assignment : no valid assignment found						    *
 ************************************************************************************************************/
enum ASSIGNMENT_ERRORS get_next_assignment(char *filename, int *exponent, int* fft_length, int* tf_depth, int* ll_saved, LINE_BUFFER *key,
		int* b1, int* b2) {
	struct ASSIGNMENT assignment;
	
	FILE *f_in;
	enum PARSE_WARNINGS value;
	char *tail;
	LINE_BUFFER line;
	unsigned int linecount = 0;
	
#ifdef EBUG
	printf("Starting GNA. Called with *fft = %d.\n", *fft_length);
#endif
	
	assignment.fft_length = 0;
	f_in = _fopen(filename, "r");
	if (NULL == f_in) {
//    printf("Can't open workfile %s in %s\n", filename, getcwd(line,sizeof(LINE_BUFFER)) );
		fprintf(stderr, "Can't open workfile %s\n\n", filename);
		return CANT_OPEN_FILE;	// nothing to open...
	}
	do {
		linecount++;
		
		value = parse_worktodo_line(f_in, &assignment, &line, &tail);
		
		if ((BLANK_LINE == value) || (NONBLANK_LINE == value))
			continue;
		if (NO_WARNING == value) {
			if (valid_assignment(assignment.exponent, assignment.fft_length))
				break;
			value = INVALID_DATA;
		}
		
		if (END_OF_FILE == value)
			break;
		fprintf(stderr, "Warning: ignoring line %u: \"%s\" in \"%s\". Reason: ", linecount, line, filename);
		switch (value) {
			case LONG_LINE:
				fprintf(stderr, "line is too long.\n");
				break;
			case NO_TEST_EQUAL:
				fprintf(stderr, "doesn't begin with Test= or DoubleCheck=.\n");
				break;
			case INVALID_FORMAT:
				fprintf(stderr, "invalid format.\n");
				break;
			case INVALID_DATA:
				fprintf(stderr, "invalid data.\n");
				break;
			default:
				fprintf(stderr, "unknown error.\n");
				break;
		}
		
		// if (LONG_LINE != value)
		//	return 2;
	} while (1);
	
	fclose(f_in);
	if (NO_WARNING == value) {
		*exponent = assignment.exponent;
		if (assignment.fft_length > 0)
			*fft_length = assignment.fft_length;
		*tf_depth = assignment.tf_depth;
		
		if (assignment.type == PFACTOR)
			*ll_saved = assignment.ll_saved;
		if (assignment.type == PMINUS1) {
			*b1 = assignment.b1;
			*b2 = assignment.b2;
		}
		
#ifdef EBUG
		printf("Struct fft is %d, *fft_length is %d\n", assignment.fft_length, *fft_length);
#endif
		
		if (key != NULL)
			strcopy(*key, assignment.hex_key, MAX_LINE_LENGTH + 1);
		
		return OK;
	} else
		fprintf(stderr, "No valid assignment found.\n\n");
	return VALID_ASSIGNMENT_NOT_FOUND;
}
Exemplo n.º 18
0
int read_JPEG_file (char * filename)
{
  /* This struct contains the JPEG decompression parameters and pointers to
   * working space (which is allocated as needed by the JPEG library).
   */
  struct jpeg_decompress_struct cinfo;
  /* We use our private extension JPEG error handler.
   * Note that this struct must live as long as the main JPEG parameter
   * struct, to avoid dangling-pointer problems.
   */
  struct my_error_mgr jerr;
  /* More stuff */
  int  infile;		/* source file */
  JSAMPARRAY buffer;		/* Output row buffer */
  int row_stride;		/* physical row width in output buffer */

  /* In this example we want to open the input file before doing anything else,
   * so that the setjmp() error recovery below can assume the file is open.
   * VERY IMPORTANT: use "b" option to _fopen() if you are on a machine that
   * requires it in order to read binary files.
   */

  if ((infile = _fopen(filename, "rb")) == NULL) {
    fprintf(stderr, "can't open %s\n", filename);
    return 0;
  }

  /* Step 1: allocate and initialize JPEG decompression object */

  /* We set up the normal JPEG error routines, then override error_exit. */
  cinfo.err = jpeg_std_error(&jerr.pub);
  jerr.pub.error_exit = my_error_exit;
  /* Establish the setjmp return context for my_error_exit to use. */
  if (setjmp(jerr.setjmp_buffer)) {
    /* If we get here, the JPEG code has signaled an error.
     * We need to clean up the JPEG object, close the input file, and return.
     */
    jpeg_destroy_decompress(&cinfo);
    _fclose(infile);
    return 0;
  }
  /* Now we can initialize the JPEG decompression object. */
  jpeg_create_decompress(&cinfo);

  /* Step 2: specify data source (eg, a file) */

  jpeg_stdio_src(&cinfo, infile);

  /* Step 3: read file parameters with jpeg_read_header() */

  (void) jpeg_read_header(&cinfo, TRUE);
  /* We can ignore the return value from jpeg_read_header since
   *   (a) suspension is not possible with the stdio data source, and
   *   (b) we passed TRUE to reject a tables-only JPEG file as an error.
   * See libjpeg.txt for more info.
   */

  /* Step 4: set parameters for decompression */

  /* In this example, we don't need to change any of the defaults set by
   * jpeg_read_header(), so we do nothing here.
   */

  /* Step 5: Start decompressor */

  (void) jpeg_start_decompress(&cinfo);
  /* We can ignore the return value since suspension is not possible
   * with the stdio data source.
   */

  /* We may need to do some setup of our own at this point before reading
   * the data.  After jpeg_start_decompress() we have the correct scaled
   * output image dimensions available, as well as the output colormap
   * if we asked for color quantization.
   * In this example, we need to make an output work buffer of the right size.
   */ 
  /* JSAMPLEs per row in output buffer */
  row_stride = cinfo.output_width * cinfo.output_components;
  /* Make a one-row-high sample array that will go away when done with image */
  buffer = (*cinfo.mem->alloc_sarray)
		((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);

  /* Step 6: while (scan lines remain to be read) */
  /*           jpeg_read_scanlines(...); */

  /* Here we use the library's state variable cinfo.output_scanline as the
   * loop counter, so that we don't have to keep track ourselves.
   */
  while (cinfo.output_scanline < cinfo.output_height) {
    /* jpeg_read_scanlines expects an array of pointers to scanlines.
     * Here the array is only one element long, but you could ask for
     * more than one scanline at a time if that's more convenient.
     */
    (void) jpeg_read_scanlines(&cinfo, buffer, 1);
    /* Assume put_scanline_someplace wants a pointer and sample count. */
    //put_scanline_someplace(buffer[0], row_stride);
    //if(cinfo.output_scanline == 9)
		mem_slide_check(FALSE);
    dump_hex("", (unsigned char*)(buffer[0]), row_stride);
  }

  /* Step 7: Finish decompression */

  (void) jpeg_finish_decompress(&cinfo);
  /* We can ignore the return value since suspension is not possible
   * with the stdio data source.
   */

  /* Step 8: Release JPEG decompression object */

  /* This is an important step since it will release a good deal of memory. */
  jpeg_destroy_decompress(&cinfo);

  /* After finish_decompress, we can close the input file.
   * Here we postpone it until after no more JPEG errors are possible,
   * so as to simplify the setjmp error logic above.  (Actually, I don't
   * think that jpeg_destroy can do an error exit, but why assume anything...)
   */
  _fclose(infile);

  /* At this point you may want to check to see whether any corrupt-data
   * warnings occurred (test whether jerr.pub.num_warnings is nonzero).
   */

  /* And we're done! */
  return 1;
}