MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / searchpath

Function searchpath

lib/lua/src/loadlib.c:472–496  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

470
471
472static const char *searchpath (lua_State *L, const char *name,
473 const char *path,
474 const char *sep,
475 const char *dirsep) {
476 luaL_Buffer buff;
477 char *pathname; /* path with name inserted */
478 char *endpathname; /* its end */
479 const char *filename;
480 /* separator is non-empty and appears in 'name'? */
481 if (*sep != '\0' && strchr(name, *sep) != NULL)
482 name = luaL_gsub(L, name, sep, dirsep); /* replace it by 'dirsep' */
483 luaL_buffinit(L, &buff);
484 /* add path to the buffer, replacing marks ('?') with the file name */
485 luaL_addgsub(&buff, path, LUA_PATH_MARK, name);
486 luaL_addchar(&buff, '\0');
487 pathname = luaL_buffaddr(&buff); /* writable list of file names */
488 endpathname = pathname + luaL_bufflen(&buff) - 1;
489 while ((filename = getnextfilename(&pathname, endpathname)) != NULL) {
490 if (readable(filename)) /* does file exist and is readable? */
491 return lua_pushstring(L, filename); /* save and return name */
492 }
493 luaL_pushresult(&buff); /* push path to create error message */
494 pusherrornotfound(L, lua_tostring(L, -1)); /* create error message */
495 return NULL; /* not found */
496}
497
498
499static int ll_searchpath (lua_State *L) {

Callers 2

ll_searchpathFunction · 0.85
findfileFunction · 0.85

Calls 8

luaL_gsubFunction · 0.85
luaL_buffinitFunction · 0.85
luaL_addgsubFunction · 0.85
getnextfilenameFunction · 0.85
readableFunction · 0.85
lua_pushstringFunction · 0.85
luaL_pushresultFunction · 0.85
pusherrornotfoundFunction · 0.85

Tested by

no test coverage detected