--- lbbs/src/file_loader.c 2025/05/25 06:48:31 1.11 +++ lbbs/src/file_loader.c 2025/11/04 13:49:51 1.18 @@ -1,35 +1,25 @@ -/*************************************************************************** - file_loader.c - description - ------------------- - Copyright : (C) 2004-2025 by Leaflet - Email : leaflet@leafok.com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * file_loader + * - shared memory based file loader + * + * Copyright (C) 2004-2025 by Leaflet + */ #include "file_loader.h" -#include "trie_dict.h" -#include "str_process.h" #include "log.h" -#include +#include "str_process.h" +#include "trie_dict.h" #include -#include +#include #include #include #include +#include +#include #include -#include #include -#include - -#define MAX_SPLIT_FILE_LINES 65536 +#include struct shm_header_t { @@ -123,11 +113,7 @@ int load_file(const char *filename) return -1; } - line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES); - if (line_total >= MAX_SPLIT_FILE_LINES) - { - log_error("split_data_lines() truncated over limit lines\n"); - } + line_total = split_data_lines(p_data, SCREEN_COLS, line_offsets, MAX_SPLIT_FILE_LINES, 1, NULL); // Allocate shared memory proj_id = (int)(time(NULL) % getpid()); @@ -155,7 +141,7 @@ int load_file(const char *filename) ((struct shm_header_t *)p_shm)->shmid = shmid; ((struct shm_header_t *)p_shm)->data_len = data_len; ((struct shm_header_t *)p_shm)->line_total = line_total; - memcpy(p_shm + sizeof(struct shm_header_t), p_data, data_len); + memcpy((char *)p_shm + sizeof(struct shm_header_t), p_data, data_len); if (munmap(p_data, data_len) < 0) { @@ -163,8 +149,8 @@ int load_file(const char *filename) return -2; } - p_data = p_shm + sizeof(struct shm_header_t); - p_line_offsets = p_data + data_len + 1; + p_data = (char *)p_shm + sizeof(struct shm_header_t); + p_line_offsets = (long *)((char *)p_data + data_len + 1); memcpy(p_line_offsets, line_offsets, sizeof(long) * (size_t)(line_total + 1)); if (shmdt(p_shm) == -1) @@ -247,8 +233,8 @@ const void *get_file_shm_readonly(const *p_data_len = ((struct shm_header_t *)p_shm)->data_len; *p_line_total = ((struct shm_header_t *)p_shm)->line_total; - *pp_data = p_shm + sizeof(struct shm_header_t); - *pp_line_offsets = *pp_data + *p_data_len + 1; + *pp_data = (char *)p_shm + sizeof(struct shm_header_t); + *pp_line_offsets = (const long *)((const char *)(*pp_data) + *p_data_len + 1); return p_shm; }