static void set_startloc( rtems_filesystem_eval_path_context_t *ctx, rtems_filesystem_global_location_t *const *global_root_ptr, rtems_filesystem_global_location_t *const *global_current_ptr ) { if (ctx->pathlen > 0) { char c = ctx->path [0]; ctx->rootloc = rtems_filesystem_global_location_obtain(global_root_ptr); if (rtems_filesystem_is_delimiter(c)) { ++ctx->path; --ctx->pathlen; ctx->startloc = rtems_filesystem_global_location_obtain( &ctx->rootloc ); } else { ctx->startloc = rtems_filesystem_global_location_obtain( global_current_ptr ); } } else { ctx->rootloc = rtems_filesystem_global_location_obtain_null(); ctx->startloc = rtems_filesystem_global_location_obtain_null(); errno = ENOENT; } }
void rtems_filesystem_eval_path_recursive( rtems_filesystem_eval_path_context_t *ctx, const char *path, size_t pathlen ) { if (pathlen > 0) { if (ctx->recursionlevel < RTEMS_FILESYSTEM_SYMLOOP_MAX) { const char *saved_path = ctx->path; size_t saved_pathlen = ctx->pathlen; if (rtems_filesystem_is_delimiter(path [0])) { rtems_filesystem_eval_path_restart(ctx, &ctx->rootloc); } ctx->path = path; ctx->pathlen = pathlen; ++ctx->recursionlevel; while (ctx->pathlen > 0) { (*ctx->currentloc.mt_entry->ops->eval_path_h)(ctx); } --ctx->recursionlevel; ctx->path = saved_path; ctx->pathlen = saved_pathlen; } else { rtems_filesystem_eval_path_error(ctx, ELOOP); } } else { rtems_filesystem_eval_path_error(ctx, ENOENT); } }
void rtems_filesystem_eval_path_eat_delimiter( rtems_filesystem_eval_path_context_t *ctx ) { const char *current = ctx->path; const char *end = current + ctx->pathlen; while (current != end && rtems_filesystem_is_delimiter(*current)) { ++current; } ctx->path = current; ctx->pathlen = (size_t) (end - current); }
static size_t get_parentpathlen(const char *path, size_t pathlen) { while (pathlen > 0) { size_t i = pathlen - 1; if (rtems_filesystem_is_delimiter(path [i])) { return pathlen; } pathlen = i; } return 0; }
static void next_token(rtems_filesystem_eval_path_context_t *ctx) { const char *begin = ctx->path; const char *end = begin + ctx->pathlen; const char *current = begin; while (current != end && !rtems_filesystem_is_delimiter(*current)) { ++current; } ctx->path = current; ctx->pathlen = (size_t) (end - current); ctx->token = begin; ctx->tokenlen = (size_t) (current - begin); }
static bool rtems_rap_match_name (rtems_rap_app_t* app, const char* name) { const char* a; /* * Assume the app name is absolute, ie points to the file on disk. This means * there is at least one delimiter in the name. */ if (strncmp (app->name, name, strlen (name)) == 0) return true; a = app->name + strlen (app->name) - 1; while (a >= app->name) { if (rtems_filesystem_is_delimiter (*a)) { const char* n = name; ++a; while (*a && *n) { if (*a == '.') { if (*n == '\0') return true; } ++a; ++n; } return false; } --a; } return false; }
bool rtems_rtl_find_file (const char* name, const char* paths, const char** file_name, size_t* size) { struct stat sb; *file_name = NULL; *size = 0; if (rtems_filesystem_is_delimiter (name[0]) || (name[0] == '.')) { if (stat (name, &sb) == 0) *file_name = rtems_rtl_strdup (name); } else if (paths) { const char* start; const char* end; int len; char* fname; start = paths; end = start + strlen (paths); len = strlen (name); while (!*file_name && (start != end)) { const char* delimiter = strchr (start, ':'); if (delimiter == NULL) delimiter = end; /* * Allocate the path fragment, separator, name, terminating nul. Form the * path then see if the stat call works. */ fname = rtems_rtl_alloc_new (RTEMS_RTL_ALLOC_OBJECT, (delimiter - start) + 1 + len + 1, true); if (!fname) { rtems_rtl_set_error (ENOMEM, "no memory searching for file"); return false; } memcpy (fname, start, delimiter - start); fname[delimiter - start] = '/'; memcpy (fname + (delimiter - start) + 1, name, len); if (rtems_rtl_trace (RTEMS_RTL_TRACE_LOAD)) printf ("rtl: find-file: path: %s\n", fname); if (stat (fname, &sb) < 0) rtems_rtl_alloc_del (RTEMS_RTL_ALLOC_OBJECT, fname); else *file_name = fname; start = delimiter; if (start != end) ++start; } } if (!*file_name) return false; *size = sb.st_size; return true; }