/[LeafOK_CVS]/lbbs/src/section_list.c
ViewVC logotype

Diff of /lbbs/src/section_list.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.66 by sysadm, Fri Dec 19 06:16:27 2025 UTC Revision 1.68 by sysadm, Wed Jan 7 14:39:16 2026 UTC
# Line 3  Line 3 
3   * section_list   * section_list
4   *   - data models and basic operations of section and article   *   - data models and basic operations of section and article
5   *   *
6   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>   * Copyright (C) 2004-2026  Leaflet <leaflet@leafok.com>
7   */   */
8    
9  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 281  int set_article_block_shm_readonly(void) Line 281  int set_article_block_shm_readonly(void)
281    
282  int detach_article_block_shm(void)  int detach_article_block_shm(void)
283  {  {
284            int shm_count;
285            size_t pool_shm_size;
286    
287          if (p_article_block_pool == NULL)          if (p_article_block_pool == NULL)
288          {          {
289                  return -1;                  return -1;
290          }          }
291    
292          for (int i = 0; i < p_article_block_pool->shm_count; i++)          shm_count = p_article_block_pool->shm_count;
293            pool_shm_size = p_article_block_pool->shm_size;
294    
295            for (int i = 0; i < shm_count; i++)
296          {          {
297                  if ((p_article_block_pool->shm_pool + i)->p_shm != NULL &&                  if ((p_article_block_pool->shm_pool + i)->p_shm != NULL &&
298                          munmap((p_article_block_pool->shm_pool + i)->p_shm, (p_article_block_pool->shm_pool + i)->shm_size) < 0)                          munmap((p_article_block_pool->shm_pool + i)->p_shm, (p_article_block_pool->shm_pool + i)->shm_size) < 0)
# Line 296  int detach_article_block_shm(void) Line 302  int detach_article_block_shm(void)
302                  }                  }
303          }          }
304    
305          if (p_article_block_pool != NULL && munmap(p_article_block_pool, p_article_block_pool->shm_size) < 0)          if (p_article_block_pool != NULL && munmap(p_article_block_pool, pool_shm_size) < 0)
306          {          {
307                  log_error("munmap() error (%d)", errno);                  log_error("munmap() error (%d)", errno);
308                  return -3;                  return -3;
# Line 373  ARTICLE *article_block_find_by_aid(int32 Line 379  ARTICLE *article_block_find_by_aid(int32
379          while (left < right)          while (left < right)
380          {          {
381                  // get block offset no less than mid value of left and right block offsets                  // get block offset no less than mid value of left and right block offsets
382                  mid = (left + right) / 2 + (left + right) % 2;                  mid = left + (right - left + 1) / 2;
383    
384                  if (aid < p_article_block_pool->p_block[mid]->articles[0].aid)                  if (aid < p_article_block_pool->p_block[mid]->articles[0].aid)
385                  {                  {
# Line 393  ARTICLE *article_block_find_by_aid(int32 Line 399  ARTICLE *article_block_find_by_aid(int32
399          // aid in the range [ aid of articles[left], aid of articles[right] ]          // aid in the range [ aid of articles[left], aid of articles[right] ]
400          while (left < right)          while (left < right)
401          {          {
402                  mid = (left + right) / 2;                  mid = left + (right - left) / 2;
403    
404                  if (aid <= p_block->articles[mid].aid)                  if (aid <= p_block->articles[mid].aid)
405                  {                  {
# Line 1217  ARTICLE *section_list_find_article_with_ Line 1223  ARTICLE *section_list_find_article_with_
1223          while (left < right)          while (left < right)
1224          {          {
1225                  // get page id no less than mid value of left page id and right page id                  // get page id no less than mid value of left page id and right page id
1226                  mid = (left + right) / 2 + (left + right) % 2;                  mid = left + (right - left + 1) / 2;
1227    
1228                  if (aid < p_section->p_page_first_article[mid]->aid)                  if (aid < p_section->p_page_first_article[mid]->aid)
1229                  {                  {
# Line 1514  int section_list_move_topic(SECTION_LIST Line 1520  int section_list_move_topic(SECTION_LIST
1520                  {                  {
1521                          p_section_src->p_article_tail = p_article->p_prior;                          p_section_src->p_article_tail = p_article->p_prior;
1522                  }                  }
1523                  if (p_section_src->p_article_head == p_article) // || p_section_src->p_article_tail == p_article                  if (p_section_src->p_article_head == p_article) // Single element list
1524                  {                  {
1525                          p_section_src->p_article_head = NULL;                          p_section_src->p_article_head = NULL;
1526                          p_section_src->p_article_tail = NULL;                          p_section_src->p_article_tail = NULL;
1527                  }                  }
1528                    else
1529                  p_article->p_prior->p_next = p_article->p_next;                  {
1530                  p_article->p_next->p_prior = p_article->p_prior;                          // Only update neighbor pointers if list is not empty after removal
1531                            p_article->p_prior->p_next = p_article->p_next;
1532                            p_article->p_next->p_prior = p_article->p_prior;
1533                    }
1534    
1535                  // Update sid of article                  // Update sid of article
1536                  p_article->sid = p_section_dest->sid;                  p_article->sid = p_section_dest->sid;


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1