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

Diff of /lbbs/src/section_list_display.c

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

Revision 1.58 by sysadm, Wed Oct 29 01:48:46 2025 UTC Revision 1.59 by sysadm, Sun Nov 2 08:13:50 2025 UTC
# Line 32  Line 32 
32  #include "str_process.h"  #include "str_process.h"
33  #include "user_info_display.h"  #include "user_info_display.h"
34  #include "user_priv.h"  #include "user_priv.h"
35    #include <errno.h>
36  #include <string.h>  #include <string.h>
37  #include <time.h>  #include <time.h>
38  #include <sys/param.h>  #include <sys/param.h>
39    
40  static int section_aid_locations[BBS_max_section] = {0};  static int32_t section_aid_locations[BBS_max_section] = {0};
41  static int section_topic_view_mode = 0;  static int section_topic_view_mode = 0;
42  static int section_topic_view_tid = -1;  static int section_topic_view_tid = -1;
43    
# Line 1163  int section_list_ex_dir_display(SECTION_ Line 1164  int section_list_ex_dir_display(SECTION_
1164    
1165          return 0;          return 0;
1166  }  }
1167    
1168    int section_aid_locations_save(int uid)
1169    {
1170            char filename[FILE_PATH_LEN];
1171            FILE *fp;
1172            int i;
1173            int ret = 0;
1174    
1175            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1176    
1177            if ((fp = fopen(filename, "wb")) == NULL)
1178            {
1179                    log_error("fopen(%s, wb) error: %d\n", filename, errno);
1180                    return -1;
1181            }
1182    
1183            for (i = 0; i < p_section_list_pool->section_count; i++)
1184            {
1185                    if (fwrite(&(p_section_list_pool->sections[i].sid), sizeof(p_section_list_pool->sections[i].sid), 1, fp) != 1)
1186                    {
1187                            log_error("fwrite(%s, sid) error\n", filename);
1188                            ret = -2;
1189                            break;
1190                    }
1191    
1192                    if (fwrite(&(section_aid_locations[i]), sizeof(section_aid_locations[i]), 1, fp) != 1)
1193                    {
1194                            log_error("fwrite(%s, aid) error\n", filename);
1195                            ret = -2;
1196                            break;
1197                    }
1198            }
1199    
1200            if (fclose(fp) < 0)
1201            {
1202                    log_error("fclose(%s) error: %d\n", filename, errno);
1203                    ret = -1;
1204            }
1205    
1206            return ret;
1207    }
1208    
1209    int section_aid_locations_load(int uid)
1210    {
1211            char filename[FILE_PATH_LEN];
1212            FILE *fp;
1213            int i;
1214            int32_t sid;
1215            int32_t aid;
1216            SECTION_LIST *p_section;
1217            int ret = 0;
1218    
1219            snprintf(filename, sizeof(filename), "%s/%d", VAR_SECTION_AID_LOC_DIR, uid);
1220    
1221            if ((fp = fopen(filename, "rb")) == NULL)
1222            {
1223                    if (errno == ENOENT) // file not exist
1224                    {
1225                            return 0;
1226                    }
1227                    log_error("fopen(%s, rb) error: %d\n", filename, errno);
1228                    return -1;
1229            }
1230    
1231            while (!feof(fp))
1232            {
1233                    if (fread(&sid, sizeof(sid), 1, fp) != 1)
1234                    {
1235                            if (ferror(fp) == 0)
1236                            {
1237                                    break;
1238                            }
1239                            log_error("fread(%s, sid) error: %d\n", filename, ferror(fp));
1240                            ret = -2;
1241                            break;
1242                    }
1243    
1244                    if (fread(&aid, sizeof(aid), 1, fp) != 1)
1245                    {
1246                            if (ferror(fp) == 0)
1247                            {
1248                                    break;
1249                            }
1250                            log_error("fread(%s, aid) error: %d\n", filename, ferror(fp));
1251                            ret = -2;
1252                            break;
1253                    }
1254    
1255                    p_section = section_list_find_by_sid(sid);
1256                    if (p_section == NULL)
1257                    {
1258                            continue; // skip section no longer exist
1259                    }
1260    
1261                    i = get_section_index(p_section);
1262                    if (i < 0)
1263                    {
1264                            log_error("get_section_index(sid=%d) error\n", sid);
1265                            ret = -3;
1266                            break;
1267                    }
1268                    section_aid_locations[i] = aid;
1269            }
1270    
1271            if (fclose(fp) < 0)
1272            {
1273                    log_error("fclose(%s) error: %d\n", filename, errno);
1274                    ret = -1;
1275            }
1276    
1277            return ret;
1278    }


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

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