Simplify module path list, removing strcpy use.
This commit is contained in:
parent
b84e58f905
commit
26c6ac3dc7
2 changed files with 7 additions and 14 deletions
|
@ -52,11 +52,6 @@ struct module
|
||||||
void * mapi_header; /* actually struct mapi_mheader_av<mapi_version> */
|
void * mapi_header; /* actually struct mapi_mheader_av<mapi_version> */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct module_path
|
|
||||||
{
|
|
||||||
char path[PATH_MAX];
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MAPI_MAGIC_HDR 0x4D410000
|
#define MAPI_MAGIC_HDR 0x4D410000
|
||||||
|
|
||||||
#define MAPI_V1 (MAPI_MAGIC_HDR | 0x1)
|
#define MAPI_V1 (MAPI_MAGIC_HDR | 0x1)
|
||||||
|
|
|
@ -130,17 +130,17 @@ modules_init(void)
|
||||||
* output - none
|
* output - none
|
||||||
* side effects - returns a module path from path
|
* side effects - returns a module path from path
|
||||||
*/
|
*/
|
||||||
static struct module_path *
|
static char *
|
||||||
mod_find_path(const char *path)
|
mod_find_path(const char *path)
|
||||||
{
|
{
|
||||||
rb_dlink_node *ptr;
|
rb_dlink_node *ptr;
|
||||||
struct module_path *mpath;
|
char *mpath;
|
||||||
|
|
||||||
RB_DLINK_FOREACH(ptr, mod_paths.head)
|
RB_DLINK_FOREACH(ptr, mod_paths.head)
|
||||||
{
|
{
|
||||||
mpath = ptr->data;
|
mpath = ptr->data;
|
||||||
|
|
||||||
if(!strcmp(path, mpath->path))
|
if(!strcmp(path, mpath))
|
||||||
return mpath;
|
return mpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,14 +156,12 @@ mod_find_path(const char *path)
|
||||||
void
|
void
|
||||||
mod_add_path(const char *path)
|
mod_add_path(const char *path)
|
||||||
{
|
{
|
||||||
struct module_path *pathst;
|
char *pathst;
|
||||||
|
|
||||||
if(mod_find_path(path))
|
if(mod_find_path(path))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pathst = rb_malloc(sizeof(struct module_path));
|
pathst = rb_strdup(path);
|
||||||
|
|
||||||
strcpy(pathst->path, path);
|
|
||||||
rb_dlinkAddAlloc(pathst, &mod_paths);
|
rb_dlinkAddAlloc(pathst, &mod_paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +286,7 @@ load_one_module(const char *path, int coremodule)
|
||||||
{
|
{
|
||||||
char modpath[PATH_MAX];
|
char modpath[PATH_MAX];
|
||||||
rb_dlink_node *pathst;
|
rb_dlink_node *pathst;
|
||||||
struct module_path *mpath;
|
const char *mpath;
|
||||||
|
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
|
@ -299,7 +297,7 @@ load_one_module(const char *path, int coremodule)
|
||||||
{
|
{
|
||||||
mpath = pathst->data;
|
mpath = pathst->data;
|
||||||
|
|
||||||
rb_snprintf(modpath, sizeof(modpath), "%s/%s", mpath->path, path);
|
rb_snprintf(modpath, sizeof(modpath), "%s/%s", mpath, path);
|
||||||
if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
|
if((strstr(modpath, "../") == NULL) && (strstr(modpath, "/..") == NULL))
|
||||||
{
|
{
|
||||||
if(stat(modpath, &statbuf) == 0)
|
if(stat(modpath, &statbuf) == 0)
|
||||||
|
|
Loading…
Reference in a new issue