Commit a85b0a6d authored by Hidenori Takeshima's avatar Hidenori Takeshima Committed by Alexandre Julliard

Added checking for mmap.

parent 01af00a5
......@@ -719,6 +719,7 @@ AC_CHECK_FUNCS(\
getsockopt \
inet_network \
memmove \
mmap \
rfork \
select \
sendmsg \
......
......@@ -203,6 +203,9 @@
/* Define if you have the memmove function. */
#undef HAVE_MEMMOVE
/* Define if you have the mmap function. */
#undef HAVE_MMAP
/* Define if you have the openpty function. */
#undef HAVE_OPENPTY
......
......@@ -38,7 +38,6 @@ char* g_lpstrFileName = NULL;
char* g_lpstrInputFile = NULL;
int b_to_binary = 0;
int b_force_overwrite = 0;
LPBYTE p_in_file = NULL;
static char* errorOpenFile = "Unable to open file.\n";
static char* errorRCFormat = "Unexpexted syntax in rc file line %i\n";
......@@ -102,9 +101,11 @@ void parse_options(int argc, char **argv)
int insert_hex (char * infile, FILE * outfile)
{
#ifdef HAVE_MMAP
unsigned int i;
int fd;
struct stat st;
LPBYTE p_in_file = NULL;
if( (fd = open( infile, O_RDONLY))==-1 )
{
......@@ -130,6 +131,45 @@ int insert_hex (char * infile, FILE * outfile)
munmap(p_in_file, st.st_size);
close(fd);
return 1;
#else /* HAVE_MMAP */
FILE* fp;
struct stat st;
unsigned int i;
int c;
fp = fopen( infile, "r" );
if ( fp == NULL )
{
fprintf(stderr, errorOpenFile );
exit(1);
}
if (fstat(fileno(fp), &st) == -1)
{
fprintf(stderr, errorOpenFile );
fclose(fp);
exit(1);
}
fprintf (outfile, "{\n '");
i = 0;
while (1)
{
c = fgetc(fp);
if ( c == EOF )
{
fprintf(stderr, errorOpenFile );
fclose(fp);
exit(1);
}
fprintf(outfile, "%02X", c);
if (++i >= st.st_size) break;
fprintf(outfile, "%s", (i == (i & 0xfffffff0)) ? "'\n '" :" ");
}
fprintf (outfile, "'\n}");
fclose(fp);
return 1;
#endif /* HAVE_MMAP */
}
int convert_to_res ()
......
......@@ -145,7 +145,9 @@ void load_res16_file( const char *name )
if ((fd = open( name, O_RDONLY )) == -1) fatal_perror( "Cannot open %s", name );
if ((fstat( fd, &st ) == -1)) fatal_perror( "Cannot stat %s", name );
if (!st.st_size) fatal_error( "%s is an empty file\n" );
#ifdef HAVE_MMAP
if ((base = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 )) == (void*)-1)
#endif /* HAVE_MMAP */
{
base = xmalloc( st.st_size );
if (read( fd, base, st.st_size ) != st.st_size)
......
......@@ -187,7 +187,9 @@ void load_res32_file( const char *name )
if ((fd = open( name, O_RDONLY )) == -1) fatal_perror( "Cannot open %s", name );
if ((fstat( fd, &st ) == -1)) fatal_perror( "Cannot stat %s", name );
if (!st.st_size) fatal_error( "%s is an empty file\n" );
#ifdef HAVE_MMAP
if ((base = mmap( NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 )) == (void*)-1)
#endif /* HAVE_MMAP */
{
base = xmalloc( st.st_size );
if (read( fd, base, st.st_size ) != st.st_size)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment