xcf_find_layer_offset_table (XcfInfo *info,
                             glong    offset)
{
  guint8 c = 0;
  guint8 buf[4] = { 0, };
  guint layer_offset;
  gint  i;

  xcf_seek_pos (info, offset, NULL);

  /* read all NULL-bytes; return if no byte was read */
  while (c == 0)
    {
      if (xcf_read_int8 (info->fp, &c, 1) == 0)
        return FALSE;
      offset++;
    }

  /* read 4 bytes into buf; ; return if no byte was read */
  buf[0] = c;
  for (i = 1; i < 4; ++i)
    {
      if (xcf_read_int8 (info->fp, &c, 1) == 0)
        return FALSE;
      buf[i] = c;
    }

  layer_offset = 0;

  /* move buf into layer_offset; set file position there */
  for (i = 0; i < 4; ++i)
    {
      layer_offset = (layer_offset << 8) | buf[i];

      if (layer_offset >= offset - 4 + i + 12)
        {
          info->cp = 0;
          xcf_seek_pos (info, offset - 4 + i, NULL);
          return TRUE;
        }
    }

  return FALSE;
}
xcf_find_layer_offset_table (XcfInfo *info,
                             glong    offset)
{
  guint8 c = 0;
  guint8 buf[4] = { 0, };
  guint layer_offset;
  gint  i;

  xcf_seek_pos (info, offset, NULL);

   
  while (c == 0)
    {
      if (xcf_read_int8 (info->fp, &c, 1) == 0)
        return FALSE;
      offset++;
    }

   
  buf[0] = c;
  for (i = 1; i < 4; ++i)
    {
      if (xcf_read_int8 (info->fp, &c, 1) == 0)
        return FALSE;
      buf[i] = c;
    }

  layer_offset = 0;

   
  for (i = 0; i < 4; ++i)
    {
      layer_offset = (layer_offset << 8) | buf[i];

      if (layer_offset >= offset - 4 + i + 12)
        {
          info->cp = 0;
          xcf_seek_pos (info, offset - 4 + i, NULL);
          return TRUE;
        }
    }

  return FALSE;
}