Beispiel #1
0
static int _sl_check_entry( _sl_Entry e, const char *function )
{
   if (!e) err_internal( function, "entry is null\n" );
#if MAA_MAGIC
   if (e->magic != SL_ENTRY_MAGIC) {
      err_warning( function,
		   "Bad magic: 0x%08x (should be 0x%08x)\n",
		   e->magic,
		   SL_ENTRY_MAGIC );
      return 1;
   }
#endif
   return 0;
}
Beispiel #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;
}