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

Diff of /lbbs/src/file_loader.c

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

Revision 1.22 by sysadm, Wed Nov 19 03:12:58 2025 UTC Revision 1.23 by sysadm, Wed Nov 19 03:29:00 2025 UTC
# Line 32  struct shm_header_t Line 32  struct shm_header_t
32  int load_file(const char *filename)  int load_file(const char *filename)
33  {  {
34          char filepath[FILE_PATH_LEN];          char filepath[FILE_PATH_LEN];
35            char shm_name[FILE_PATH_LEN];
36          int fd;          int fd;
37          struct stat sb;          struct stat sb;
38          void *p_data;          void *p_data;
# Line 88  int load_file(const char *filename) Line 89  int load_file(const char *filename)
89    
90          strncpy(filepath, filename, sizeof(filepath) - 1);          strncpy(filepath, filename, sizeof(filepath) - 1);
91          filepath[sizeof(filepath) - 1] = '\0';          filepath[sizeof(filepath) - 1] = '\0';
92            snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath));
93    
94          if ((fd = shm_open(basename(filepath), O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)          if ((fd = shm_open(shm_name, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1)
95          {          {
96                  log_error("shm_open(%s) error (%d)\n", basename(filepath), errno);                  log_error("shm_open(%s) error (%d)\n", shm_name, errno);
97                  return -2;                  return -2;
98          }          }
99          if (ftruncate(fd, (off_t)size) == -1)          if (ftruncate(fd, (off_t)size) == -1)
# Line 143  int load_file(const char *filename) Line 145  int load_file(const char *filename)
145  int unload_file(const char *filename)  int unload_file(const char *filename)
146  {  {
147          char filepath[FILE_PATH_LEN];          char filepath[FILE_PATH_LEN];
148            char shm_name[FILE_PATH_LEN];
149    
150          if (filename == NULL)          if (filename == NULL)
151          {          {
# Line 152  int unload_file(const char *filename) Line 155  int unload_file(const char *filename)
155    
156          strncpy(filepath, filename, sizeof(filepath) - 1);          strncpy(filepath, filename, sizeof(filepath) - 1);
157          filepath[sizeof(filepath) - 1] = '\0';          filepath[sizeof(filepath) - 1] = '\0';
158            snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath));
159    
160          if (shm_unlink(basename(filepath)) == -1 && errno != ENOENT)          if (shm_unlink(shm_name) == -1 && errno != ENOENT)
161          {          {
162                  log_error("shm_unlink(%s) error (%d)\n", basename(filepath), errno);                  log_error("shm_unlink(%s) error (%d)\n", shm_name, errno);
163                  return -2;                  return -2;
164          }          }
165    
# Line 165  int unload_file(const char *filename) Line 169  int unload_file(const char *filename)
169  void *get_file_shm_readonly(const char *filename, size_t *p_data_len, long *p_line_total, const void **pp_data, const long **pp_line_offsets)  void *get_file_shm_readonly(const char *filename, size_t *p_data_len, long *p_line_total, const void **pp_data, const long **pp_line_offsets)
170  {  {
171          char filepath[FILE_PATH_LEN];          char filepath[FILE_PATH_LEN];
172            char shm_name[FILE_PATH_LEN];
173          int fd;          int fd;
174          void *p_shm = NULL;          void *p_shm = NULL;
175          struct stat sb;          struct stat sb;
# Line 178  void *get_file_shm_readonly(const char * Line 183  void *get_file_shm_readonly(const char *
183    
184          strncpy(filepath, filename, sizeof(filepath) - 1);          strncpy(filepath, filename, sizeof(filepath) - 1);
185          filepath[sizeof(filepath) - 1] = '\0';          filepath[sizeof(filepath) - 1] = '\0';
186            snprintf(shm_name, sizeof(shm_name), "/%s", basename(filepath));
187    
188          if ((fd = shm_open(basename(filepath), O_RDONLY, 0600)) == -1)          if ((fd = shm_open(shm_name, O_RDONLY, 0600)) == -1)
189          {          {
190                  log_error("shm_open(%s) error (%d)\n", basename(filepath), errno);                  log_error("shm_open(%s) error (%d)\n", shm_name, errno);
191                  return NULL;                  return NULL;
192          }          }
193    


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

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