Return TypeFunction nameArguments
hzEcodeInitCountryCodes(void)

Declared in file: hzIpaddr.h
Defined in file : hzIpaddr.cpp

Function Logic:

0:START 1:shm_open fd 2:fd<0 3:Return hzerr(E_INITFAIL,Cannot initialize shared memory segment (deltaCountryCodes)\n) 4:fstat mmap pCC_buf 5:!pCC_buf 6:Return hzerr(E_INITFAIL,Could not map Shared memory segment. Errno %d,errno) 7:pShort s_CC_max s_CC_offsets pShort s_CC_buffer 8:n<=s_CC_max; 9:s_CC_div s_CC_start 10:Return rc

Function body:

hzEcode InitCountryCodes (void)
{
   _hzfunc(__func__) ;
   ifstream    is ;
   FSTAT       fs ;
   char*       pCC_buf ;
   uint16_t*   pShort ;
   uint32_t    n ;
   int32_t     fd ;
   hzEcode     rc = E_OK ;
    fd = shm_open("deltaCountryCodes", O_RDONLY, 0);
   if (fd < 0)
       return hzerr(E_INITFAIL, "Cannot initialize shared memory segment (deltaCountryCodes)\n") ;
   fstat(fd, &fs);
    threadLog("Set fd to %d\n", fd) ;
   pCC_buf = (char*) mmap(0,fs.st_size, PROT_READ, MAP_SHARED, fd, 0);
   if (!pCC_buf)
       return hzerr(E_INITFAIL, "Could not map Shared memory segment. Errno %d", errno) ;
   threadLog("Country codes mem at %p, size is %d\n", pCC_buf, fs.st_size) ;
   pShort = (uint16_t*) pCC_buf ;
   s_CC_max = *pShort++ ;
   threadLog("Total codes %d\n", s_CC_max) ;
   s_CC_offsets = pShort ;
   threadLog("Offsets at %p\n", s_CC_offsets) ;
   pShort += s_CC_max ;
   s_CC_buffer = (char*) pShort ;
   threadLog("Buffer at %p\n", s_CC_buffer) ;
   for (n = 2; n <&eq; s_CC_max ; n *= 2);
   s_CC_div = n / 2;
   s_CC_start = n - 1;
   threadLog("Total codes %d (div %d start %d)\n\n", s_CC_max, s_CC_div, s_CC_start) ;
   /*
   **  for (n = 0 ; n < s_CC_max ; n++)
   **    threadLog("%s -> %s (%d)\n", s_CC_buffer + s_CC_offsets[n], s_CC_buffer + s_CC_offsets[n] + 3, s_CC_offsets[n]) ;
   **      */
   return rc ;
}