예제 #1
0
dictData *dict_data_open( const char *filename, int computeCRC )
{
   dictData    *h = NULL;
//   struct stat sb;
   int         j;

   if (!filename)
      return NULL;

   h = xmalloc( sizeof( struct dictData ) );

   memset( h, 0, sizeof( struct dictData ) );
   h->initialized = 0;

   if (dict_read_header( filename, h, computeCRC )) {
     return 0; /*
      err_fatal( __func__,
     "\"%s\" not in text or dzip format\n", filename );*/
   }

   h->fd = gd_fopen( filename, "rb" );

   if ( !h->fd )
   {
     return 0;
      /*err_fatal_errno( __func__,
           "Cannot open data file \"%s\"\n", filename );*/
    }

   fseek( h->fd, 0, SEEK_END );

   h->size = ftell( h->fd );

   for (j = 0; j < DICT_CACHE_SIZE; j++) {
      h->cache[j].chunk    = -1;
      h->cache[j].stamp    = -1;
      h->cache[j].inBuffer = NULL;
      h->cache[j].count    = 0;
   }
   
   return h;
}
예제 #2
0
dictData *dict_data_open( const char *filename, int computeCRC )
{
   dictData    *h = NULL;
   struct stat sb;
   int         j;

   if (!filename)
      return NULL;

   h = xmalloc( sizeof( struct dictData ) );

   memset( h, 0, sizeof( struct dictData ) );
   h->initialized = 0;

   if (stat( filename, &sb ) || !S_ISREG(sb.st_mode)) {
      err_warning( __func__,
		   "%s is not a regular file -- ignoring\n", filename );
      return h;
   }
   
   if (dict_read_header( filename, h, computeCRC )) {
      err_fatal( __func__,
		 "\"%s\" not in text or dzip format\n", filename );
   }
   
   if ((h->fd = open( filename, O_RDONLY )) < 0)
      err_fatal_errno( __func__,
		       "Cannot open data file \"%s\"\n", filename );
   if (fstat( h->fd, &sb ))
      err_fatal_errno( __func__,
		       "Cannot stat data file \"%s\"\n", filename );
   h->size = sb.st_size;

   if (mmap_mode){
#ifdef HAVE_MMAP
      h->start = mmap( NULL, h->size, PROT_READ, MAP_SHARED, h->fd, 0 );
      if ((void *)h->start == (void *)(-1))
	 err_fatal_errno(
	    __func__,
	    "Cannot mmap data file \"%s\"\n", filename );
#else
      err_fatal (__func__, "This should not happen");
#endif
   }else{
      h->start = xmalloc (h->size);
      if (-1 == read (h->fd, (char *) h->start, h->size))
	 err_fatal_errno (
	    __func__,
	    "Cannot read data file \"%s\"\n", filename );

      close (h -> fd);
      h -> fd = 0;
   }

   h->end = h->start + h->size;

   for (j = 0; j < DICT_CACHE_SIZE; j++) {
      h->cache[j].chunk    = -1;
      h->cache[j].stamp    = -1;
      h->cache[j].inBuffer = NULL;
      h->cache[j].count    = 0;
   }
   
   return h;
}
예제 #3
0
dictData *dict_data_open( const char *filename, int computeCRC )
{
   dictData    *h = NULL;
//   struct stat sb;
   int         j;

   if (!filename)
      return NULL;

   h = xmalloc( sizeof( struct dictData ) );

   memset( h, 0, sizeof( struct dictData ) );
#ifdef __WIN32
   h->fd = INVALID_HANDLE_VALUE;
#endif
   h->initialized = 0;

   for(;;)
   {
     if (dict_read_header( filename, h, computeCRC )) {
       break; /*
        err_fatal( __func__,
       "\"%s\" not in text or dzip format\n", filename );*/
     }

#ifdef __WIN32
     wchar_t wname[16384];
     if( MultiByteToWideChar( CP_UTF8, 0, filename, -1, wname, 16384 ) == 0 )
       break;

     h->fd = CreateFileW( wname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
                          OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0);
     if( h->fd == INVALID_HANDLE_VALUE )
       break;

     h->size = GetFileSize( h->fd, 0 );
#else
     h->fd = gd_fopen( filename, "rb" );

     if ( !h->fd )
     {
       break;
        /*err_fatal_errno( __func__,
             "Cannot open data file \"%s\"\n", filename );*/
      }

     fseek( h->fd, 0, SEEK_END );

     h->size = ftell( h->fd );
#endif

     for (j = 0; j < DICT_CACHE_SIZE; j++) {
        h->cache[j].chunk    = -1;
        h->cache[j].stamp    = -1;
        h->cache[j].inBuffer = NULL;
        h->cache[j].count    = 0;
     }

     return h;
   }
   dict_data_close( h );
   return( 0 );
}