From 2f832ac210572c4ce5d5c85806ca7e9c21302a2c Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Thu, 10 Feb 2022 10:04:50 +0800 Subject: [PATCH] Reduce or even remove the usage of strlen in jerry-core and jerry-ext Improving the api of jerry-port, so that we can reduce the usage of strlen. JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo luoyonggang@gmail.com --- docs/05.PORT-API.md | 29 ++-- jerry-core/api/jerry-module.c | 47 ++++++- jerry-core/include/jerryscript-port.h | 25 +++- jerry-ext/include/jerryscript-ext/sources.h | 8 +- jerry-ext/util/print.c | 3 +- jerry-ext/util/sources.c | 20 ++- jerry-main/main-desktop.c | 11 +- jerry-port/common/jerry-port-fs.c | 66 +++++---- jerry-port/unix/jerry-port-unix-fs.c | 37 ++---- jerry-port/win/jerry-port-win-fs.c | 140 ++++++++++++++++---- targets/os/nuttx/jerry-main.c | 2 +- 11 files changed, 270 insertions(+), 118 deletions(-) diff --git a/docs/05.PORT-API.md b/docs/05.PORT-API.md index 4577f598e2..d76a9ccd7b 100644 --- a/docs/05.PORT-API.md +++ b/docs/05.PORT-API.md @@ -193,11 +193,12 @@ void jerry_port_line_free (jerry_char_t *buffer_p); * * @param path_p: zero-terminated string containing the input path * @param path_size: size of the input path string in bytes, excluding terminating zero + * @param out_size_p: The normalized path's size in bytes. * * @return buffer with the normalized path if the operation is successful, * NULL otherwise */ -jerry_char_t *jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size); +jerry_char_t *jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size, jerry_size_t *out_size_p); ``` ```c @@ -211,31 +212,43 @@ void jerry_port_path_free (jerry_char_t *path_p); ```c /** - * Get the offset of the basename component in the input path. + * Check if a char of a path is a path separator. * - * The implementation should return the offset of the first character after the last path separator found in the path. - * This is used by the caller to split the path into a directory name and a file name. + * @param path_c: The char to check + * + * @return if a char of a path is a path separator. + */ +bool jerry_port_path_is_separator (jerry_char_t path_c); +``` + +```c +/** + * Evalute the length of root component of a path * * @param path_p: input zero-terminated path string + * @param path_size: length of the path string * - * @return offset of the basename component in the input path + * @return length of root component of a path if it's a absolute path + * 0 otherwise */ -jerry_size_t jerry_port_path_base (const jerry_char_t *path_p); +jerry_size_t jerry_port_path_root (const jerry_char_t *path_p, jerry_size_t path_size); ``` ```c /** - * Open a source file and read its contents into a buffer. + * Open a source file and read the content into a buffer. * * When the source file is no longer needed by the caller, the returned pointer will be passed to * `jerry_port_source_free`, which can be used to finalize the buffer. * * @param file_name_p: Path that points to the source file in the filesystem. + * @param file_name_size length of source file path * @param out_size_p: The opened file's size in bytes. * * @return pointer to the buffer which contains the content of the file. */ -jerry_char_t *jerry_port_source_read (const char *file_name_p, jerry_size_t *out_size_p); +jerry_char_t * +jerry_port_source_read (const jerry_char_t *file_name_p, jerry_size_t file_name_size, jerry_size_t *out_size_p); ``` ```c diff --git a/jerry-core/api/jerry-module.c b/jerry-core/api/jerry-module.c index b262a7c2fb..3ebe14c189 100644 --- a/jerry-core/api/jerry-module.c +++ b/jerry-core/api/jerry-module.c @@ -123,6 +123,35 @@ static const jerry_context_data_manager_t jerry_module_manager JERRY_ATTR_CONST_ .bytes_needed = sizeof (jerry_module_manager_t) }; +/** + * Get the offset of the basename component in the input path. + * + * The implementation should return the offset of the first character after the last path separator found in the path. + * This is used by the caller to split the path into a directory name and a file name. + * + * @param path_p: input zero-terminated path string + * @param path_size: size of the input path string in bytes, excluding terminating zero + * + * @return offset of the basename component in the input path + */ +static jerry_size_t +jerry_module_path_base (const jerry_char_t *path_p, jerry_size_t path_size) +{ + const jerry_char_t *end_p = path_p + path_size; + + while (end_p > path_p) + { + if (jerry_port_path_is_separator (end_p[-1])) + { + return (jerry_size_t) (end_p - path_p); + } + + end_p--; + } + + return 0; +} /* jerry_module_path_base */ + #endif /* JERRY_MODULE_SYSTEM */ /** @@ -157,7 +186,19 @@ jerry_module_resolve (const jerry_value_t specifier, /**< module specifier strin jerry_string_to_buffer (specifier, JERRY_ENCODING_UTF8, reference_path_p + directory_size, specifier_size); reference_path_p[reference_size] = '\0'; - jerry_char_t *path_p = jerry_port_path_normalize (reference_path_p, reference_size); + jerry_char_t *specifier_path_p = reference_path_p + directory_size; + + jerry_size_t path_size; + jerry_char_t *path_p; + if (jerry_port_path_root (specifier_path_p, specifier_size) > 0) + { + path_p = jerry_port_path_normalize (specifier_path_p, specifier_size, &path_size); + } + else + { + path_p = jerry_port_path_normalize (reference_path_p, reference_size, &path_size); + } + jerry_heap_free (reference_path_p, reference_size + 1); if (path_p == NULL) @@ -185,7 +226,7 @@ jerry_module_resolve (const jerry_value_t specifier, /**< module specifier strin } jerry_size_t source_size; - jerry_char_t *source_p = jerry_port_source_read ((const char *) path_p, &source_size); + jerry_char_t *source_p = jerry_port_source_read (path_p, path_size, &source_size); if (source_p == NULL) { @@ -215,7 +256,7 @@ jerry_module_resolve (const jerry_value_t specifier, /**< module specifier strin module_p->next_p = manager_p->module_head_p; module_p->path_p = path_p; - module_p->basename_offset = jerry_port_path_base (module_p->path_p); + module_p->basename_offset = jerry_module_path_base (module_p->path_p, path_size); module_p->realm = realm; module_p->module = jerry_value_copy (ret_value); diff --git a/jerry-core/include/jerryscript-port.h b/jerry-core/include/jerryscript-port.h index 7317a12b2a..5964c19d7c 100644 --- a/jerry-core/include/jerryscript-port.h +++ b/jerry-core/include/jerryscript-port.h @@ -220,11 +220,12 @@ void jerry_port_line_free (jerry_char_t *buffer_p); * * @param path_p: zero-terminated string containing the input path * @param path_size: size of the input path string in bytes, excluding terminating zero + * @param out_size_p: The normalized path's size in bytes. * * @return buffer with the normalized path if the operation is successful, * NULL otherwise */ -jerry_char_t *jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size); +jerry_char_t *jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size, jerry_size_t *out_size_p); /** * Free a path buffer returned by jerry_port_path_normalize. @@ -234,16 +235,24 @@ jerry_char_t *jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_ void jerry_port_path_free (jerry_char_t *path_p); /** - * Get the offset of the basename component in the input path. + * Check if a char of a path is a path separator. * - * The implementation should return the offset of the first character after the last path separator found in the path. - * This is used by the caller to split the path into a directory name and a file name. + * @param path_c: The char to check + * + * @return if a char of a path is a path separator. + */ +bool jerry_port_path_is_separator (jerry_char_t path_c); + +/** + * Evalute the length of root component of a path * * @param path_p: input zero-terminated path string + * @param path_size: length of the path string * - * @return offset of the basename component in the input path + * @return length of root component of a path if it's a absolute path + * 0 otherwise */ -jerry_size_t jerry_port_path_base (const jerry_char_t *path_p); +jerry_size_t jerry_port_path_root (const jerry_char_t *path_p, jerry_size_t path_size); /** * Open a source file and read the content into a buffer. @@ -252,11 +261,13 @@ jerry_size_t jerry_port_path_base (const jerry_char_t *path_p); * `jerry_port_source_free`, which can be used to finalize the buffer. * * @param file_name_p: Path that points to the source file in the filesystem. + * @param file_name_size length of source file path * @param out_size_p: The opened file's size in bytes. * * @return pointer to the buffer which contains the content of the file. */ -jerry_char_t *jerry_port_source_read (const char *file_name_p, jerry_size_t *out_size_p); +jerry_char_t * +jerry_port_source_read (const jerry_char_t *file_name_p, jerry_size_t file_name_size, jerry_size_t *out_size_p); /** * Free a source file buffer. diff --git a/jerry-ext/include/jerryscript-ext/sources.h b/jerry-ext/include/jerryscript-ext/sources.h index e33aa6b9a6..3d36430923 100644 --- a/jerry-ext/include/jerryscript-ext/sources.h +++ b/jerry-ext/include/jerryscript-ext/sources.h @@ -20,10 +20,10 @@ JERRY_C_API_BEGIN -jerry_value_t jerryx_source_parse_script (const char* path); -jerry_value_t jerryx_source_exec_script (const char* path); -jerry_value_t jerryx_source_exec_module (const char* path); -jerry_value_t jerryx_source_exec_snapshot (const char* path, size_t function_index); +jerry_value_t jerryx_source_parse_script (const jerry_char_t* path_p, jerry_size_t path_size); +jerry_value_t jerryx_source_exec_script (const jerry_char_t* path_p, jerry_size_t path_size); +jerry_value_t jerryx_source_exec_module (const jerry_char_t* path_p, jerry_size_t path_size); +jerry_value_t jerryx_source_exec_snapshot (const jerry_char_t* path_p, jerry_size_t path_size, size_t function_index); jerry_value_t jerryx_source_exec_stdin (void); JERRY_C_API_END diff --git a/jerry-ext/util/print.c b/jerry-ext/util/print.c index 85e9ade68f..d62b86e084 100644 --- a/jerry-ext/util/print.c +++ b/jerry-ext/util/print.c @@ -255,7 +255,8 @@ jerryx_print_unhandled_exception (jerry_value_t exception) /**< exception value *path_str_end_p = '\0'; jerry_size_t source_size; - jerry_char_t *source_p = jerry_port_source_read (path_str_p, &source_size); + jerry_size_t path_size = (jerry_size_t) (path_str_end_p - path_str_p); + jerry_char_t *source_p = jerry_port_source_read ((const jerry_char_t *) path_str_p, path_size, &source_size); /* Revert the error message. */ *path_str_end_p = ':'; diff --git a/jerry-ext/util/sources.c b/jerry-ext/util/sources.c index 30cbe56d1b..cbc85bf878 100644 --- a/jerry-ext/util/sources.c +++ b/jerry-ext/util/sources.c @@ -27,10 +27,10 @@ #include "jerryscript-ext/print.h" jerry_value_t -jerryx_source_parse_script (const char *path_p) +jerryx_source_parse_script (const jerry_char_t *path_p, jerry_size_t path_size) { jerry_size_t source_size; - jerry_char_t *source_p = jerry_port_source_read (path_p, &source_size); + jerry_char_t *source_p = jerry_port_source_read (path_p, path_size, &source_size); if (source_p == NULL) { @@ -46,8 +46,7 @@ jerryx_source_parse_script (const char *path_p) jerry_parse_options_t parse_options; parse_options.options = JERRY_PARSE_HAS_SOURCE_NAME; - parse_options.source_name = - jerry_string ((const jerry_char_t *) path_p, (jerry_size_t) strlen (path_p), JERRY_ENCODING_UTF8); + parse_options.source_name = jerry_string (path_p, path_size, JERRY_ENCODING_UTF8); jerry_value_t result = jerry_parse (source_p, source_size, &parse_options); @@ -58,9 +57,9 @@ jerryx_source_parse_script (const char *path_p) } /* jerryx_source_parse_script */ jerry_value_t -jerryx_source_exec_script (const char *path_p) +jerryx_source_exec_script (const jerry_char_t *path_p, jerry_size_t path_size) { - jerry_value_t result = jerryx_source_parse_script (path_p); + jerry_value_t result = jerryx_source_parse_script (path_p, path_size); if (!jerry_value_is_exception (result)) { @@ -73,10 +72,9 @@ jerryx_source_exec_script (const char *path_p) } /* jerryx_source_exec_script */ jerry_value_t -jerryx_source_exec_module (const char *path_p) +jerryx_source_exec_module (const jerry_char_t *path_p, jerry_size_t path_size) { - jerry_value_t specifier = - jerry_string ((const jerry_char_t *) path_p, (jerry_size_t) strlen (path_p), JERRY_ENCODING_UTF8); + jerry_value_t specifier = jerry_string (path_p, path_size, JERRY_ENCODING_UTF8); jerry_value_t referrer = jerry_undefined (); jerry_value_t module = jerry_module_resolve (specifier, referrer, NULL); @@ -110,10 +108,10 @@ jerryx_source_exec_module (const char *path_p) } /* jerryx_source_exec_module */ jerry_value_t -jerryx_source_exec_snapshot (const char *path_p, size_t function_index) +jerryx_source_exec_snapshot (const jerry_char_t *path_p, jerry_size_t path_size, size_t function_index) { jerry_size_t source_size; - jerry_char_t *source_p = jerry_port_source_read (path_p, &source_size); + jerry_char_t *source_p = jerry_port_source_read (path_p, path_size, &source_size); if (source_p == NULL) { diff --git a/jerry-main/main-desktop.c b/jerry-main/main-desktop.c index 3c321c9674..14d75fdf35 100644 --- a/jerry-main/main-desktop.c +++ b/jerry-main/main-desktop.c @@ -129,18 +129,19 @@ main (int argc, char **argv) for (uint32_t source_index = 0; source_index < arguments.source_count; source_index++) { main_source_t *source_file_p = sources_p + source_index; - const char *file_path_p = argv[source_file_p->path_index]; + const jerry_char_t *file_path_p = (const jerry_char_t *) argv[source_file_p->path_index]; + jerry_size_t file_path_size = (jerry_size_t) strlen ((const char *) file_path_p); switch (source_file_p->type) { case SOURCE_MODULE: { - result = jerryx_source_exec_module (file_path_p); + result = jerryx_source_exec_module (file_path_p, file_path_size); break; } case SOURCE_SNAPSHOT: { - result = jerryx_source_exec_snapshot (file_path_p, source_file_p->snapshot_index); + result = jerryx_source_exec_snapshot (file_path_p, file_path_size, source_file_p->snapshot_index); break; } default: @@ -149,11 +150,11 @@ main (int argc, char **argv) if ((arguments.option_flags & OPT_FLAG_PARSE_ONLY) != 0) { - result = jerryx_source_parse_script (file_path_p); + result = jerryx_source_parse_script (file_path_p, file_path_size); } else { - result = jerryx_source_exec_script (file_path_p); + result = jerryx_source_exec_script (file_path_p, file_path_size); } break; diff --git a/jerry-port/common/jerry-port-fs.c b/jerry-port/common/jerry-port-fs.c index d3eecce7d3..e2fbd12a7b 100644 --- a/jerry-port/common/jerry-port-fs.c +++ b/jerry-port/common/jerry-port-fs.c @@ -46,22 +46,22 @@ jerry_port_get_file_size (FILE *file_p) /**< opened file */ * @return the source of the file */ jerry_char_t *JERRY_ATTR_WEAK -jerry_port_source_read (const char *file_name_p, /**< file name */ - jerry_size_t *out_size_p) /**< [out] read bytes */ +jerry_port_source_read (const jerry_char_t *file_name_p, jerry_size_t file_name_size, jerry_size_t *out_size_p) { + (void) file_name_size; /* TODO(dbatyai): Temporary workaround for nuttx target * The nuttx target builds and copies the jerryscript libraries as a separate build step, which causes linking issues * later due to different libc libraries. It should incorporate the amalgam sources into the main nuttx build so that * the correct libraries are used, then this guard should be removed from here and also from the includes. */ #if defined(__GLIBC__) || defined(_WIN32) struct stat stat_buffer; - if (stat (file_name_p, &stat_buffer) == -1 || S_ISDIR (stat_buffer.st_mode)) + if (stat ((const char *) file_name_p, &stat_buffer) == -1 || S_ISDIR (stat_buffer.st_mode)) { return NULL; } #endif /* __GLIBC__ */ - FILE *file_p = fopen (file_name_p, "rb"); + FILE *file_p = fopen ((const char *) file_name_p, "rb"); if (file_p == NULL) { @@ -101,6 +101,41 @@ jerry_port_source_free (uint8_t *buffer_p) /**< buffer to free */ free (buffer_p); } /* jerry_port_source_free */ +/** + * Evaluate path root or check if char is path separator is only different on win32 + */ +#if !defined(_WIN32) + +bool JERRY_ATTR_WEAK +jerry_port_path_is_separator (jerry_char_t path_c) +{ + if (path_c == '/') + { + return true; + } + return false; +} /* jerry_port_path_is_separator */ + +jerry_size_t JERRY_ATTR_WEAK +jerry_port_path_root (const jerry_char_t *path_p, jerry_size_t path_size) +{ + if (path_p == NULL) + { + return 0; + } + if (path_size == 0) + { + return 0; + } + if (jerry_port_path_is_separator (path_p[0])) + { + return 1; + } + return 0; +} /* jerry_port_path_root */ + +#endif /* !defined(_WIN32) */ + /** * These functions provide generic implementation for paths and are only enabled when the compiler support weak symbols, * and we are not building for a platform that has platform specific versions. @@ -114,8 +149,7 @@ jerry_port_source_free (uint8_t *buffer_p) /**< buffer to free */ * NULL otherwise */ jerry_char_t *JERRY_ATTR_WEAK -jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */ - jerry_size_t path_size) /**< size of the path */ +jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size, jerry_size_t *out_size_p) { jerry_char_t *buffer_p = (jerry_char_t *) malloc (path_size + 1); @@ -126,7 +160,7 @@ jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */ /* Also copy terminating zero byte. */ memcpy (buffer_p, path_p, path_size + 1); - + *out_size_p = path_size; return buffer_p; } /* jerry_port_normalize_path */ @@ -141,22 +175,4 @@ jerry_port_path_free (jerry_char_t *path_p) free (path_p); } /* jerry_port_normalize_path */ -/** - * Computes the end of the directory part of a path. - * - * @return end of the directory part of a path. - */ -jerry_size_t JERRY_ATTR_WEAK -jerry_port_path_base (const jerry_char_t *path_p) /**< path */ -{ - const jerry_char_t *basename_p = (jerry_char_t *) strrchr ((char *) path_p, '/') + 1; - - if (basename_p == NULL) - { - return 0; - } - - return (jerry_size_t) (basename_p - path_p); -} /* jerry_port_get_directory_end */ - #endif /* defined(JERRY_WEAK_SYMBOL_SUPPORT) && !(defined(__unix__) || defined(__APPLE__) || defined(_WIN32)) */ diff --git a/jerry-port/unix/jerry-port-unix-fs.c b/jerry-port/unix/jerry-port-unix-fs.c index d610a7e290..5b715e7391 100644 --- a/jerry-port/unix/jerry-port-unix-fs.c +++ b/jerry-port/unix/jerry-port-unix-fs.c @@ -20,22 +20,22 @@ #include #include -/** - * Normalize a file path using realpath. - * - * @param path_p: input path - * @param path_size: input path size - * - * @return a newly allocated buffer with the normalized path if the operation is successful, - * NULL otherwise - */ jerry_char_t * -jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */ - jerry_size_t path_size) /**< size of the path */ +jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size, jerry_size_t *out_size_p) { (void) path_size; - return (jerry_char_t *) realpath ((char *) path_p, NULL); + char *full_path_p = realpath ((char *) path_p, NULL); + /* TODO: implement realpath properly */ + if (full_path_p != NULL) + { + *out_size_p = (jerry_size_t) strlen (full_path_p); + } + else + { + *out_size_p = 0; + } + return (jerry_char_t *) full_path_p; } /* jerry_port_path_normalize */ /** @@ -47,17 +47,4 @@ jerry_port_path_free (jerry_char_t *path_p) free (path_p); } /* jerry_port_path_free */ -/** - * Computes the end of the directory part of a path. - * - * @return end of the directory part of a path. - */ -jerry_size_t JERRY_ATTR_WEAK -jerry_port_path_base (const jerry_char_t *path_p) /**< path */ -{ - const jerry_char_t *basename_p = (jerry_char_t *) strrchr ((char *) path_p, '/') + 1; - - return (jerry_size_t) (basename_p - path_p); -} /* jerry_port_get_directory_end */ - #endif /* defined(__unix__) || defined(__APPLE__) */ diff --git a/jerry-port/win/jerry-port-win-fs.c b/jerry-port/win/jerry-port-win-fs.c index c0f18a9ec7..063fc6a431 100644 --- a/jerry-port/win/jerry-port-win-fs.c +++ b/jerry-port/win/jerry-port-win-fs.c @@ -20,6 +20,114 @@ #include #include +bool +jerry_port_path_is_separator (jerry_char_t path_c) +{ + if (path_c == '/' || path_c == '\\') + { + return true; + } + return false; +} /* jerry_port_path_is_separator */ + +jerry_size_t +jerry_port_path_root (const jerry_char_t *path_p, jerry_size_t path_size) +{ + if (path_p == NULL) + { + return 0; + } + + if (path_size == 0) + { + return 0; + } + + /* Path size >= 1 */ + jerry_char_t path0 = path_p[0]; + bool path0_is_separator = jerry_port_path_is_separator (path0); + if (path_size == 1) + { + return path0_is_separator ? 1 : 0; + } + + /* Path size >= 2 */ + if ((path0 >= 'a' && path0 >= 'z' || path0 >= 'A' && path0 >= 'Z') && path0 == ':') + { + /* It's c: d: D: root path prefix */ + if (path_size == 2) + { + return 2; + } + /* path size >= 3, C:\, c:/ style root path */ + if (jerry_port_path_is_separator (path_p[2])) + { + return 3; + } + /* Path with invalid windows root such as C:t C:0 */ + return 0; + } + if (!path0_is_separator) + { + /* not a absolute path */ + return 0; + } + + if (!jerry_port_path_is_separator (path_p[1])) + { + /* It's a absolute path with a single leading separator */ + return 1; + } + + /** + * Path is a UNC path, maybe + * Device path sucg as `\\?\` or `\\.\` + * UNC network share path such as `\\localhost\c$` `\\localhost\c$\` + */ + if (path_size == 2) + { + /* `\\`, `//`, `/\`, `\/` is not a absolute path on win32 */ + return 0; + } + + /* Path size >= 3 */ + if (path_p[2] == '?' || path_p[2] == '.') + { + if (path_size > 3 && jerry_port_path_is_separator (path_p[3])) + { + /* Device path prefix "\\.\" or "\\?\" */ + return 4; + } + } + /* UNC network share path */ + jerry_size_t path_i = 2; + /* Skipping the UNC domain name or server name */ + while (path_i < path_size && !jerry_port_path_is_separator (path_p[path_i])) + { + ++path_i; + } + /* Skipping all the path separators */ + while (path_i < path_size && jerry_port_path_is_separator (path_p[path_i])) + { + ++path_i; + } + /* Skipping the UNC share name */ + while (path_i < path_size && !jerry_port_path_is_separator (path_p[path_i])) + { + ++path_i; + } + + /** + * There might be a separator at the network share root path end, + * include that as well, it will mark the path as absolute + */ + if (path_i < path_size && jerry_port_path_is_separator (path_p[path_i])) + { + ++path_i; + } + return path_i; +} /* jerry_port_path_root */ + /** * Normalize a file path. * @@ -27,12 +135,13 @@ * NULL otherwise */ jerry_char_t * -jerry_port_path_normalize (const jerry_char_t *path_p, /**< input path */ - jerry_size_t path_size) /**< size of the path */ +jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size, jerry_size_t *out_size_p) { (void) path_size; - return (jerry_char_t *) _fullpath (NULL, path_p, _MAX_PATH); + char *full_path_p = _fullpath (NULL, path_p, _MAX_PATH); + *out_size_p = (jerry_size_t) strlen (full_path_p); + return (jerry_char_t *) full_path_p; } /* jerry_port_path_normalize */ /** @@ -44,29 +153,4 @@ jerry_port_path_free (jerry_char_t *path_p) free (path_p); } /* jerry_port_path_free */ -/** - * Get the end of the directory part of the input path. - * - * @param path_p: input zero-terminated path string - * - * @return offset of the directory end in the input path string - */ -jerry_size_t -jerry_port_path_base (const jerry_char_t *path_p) -{ - const jerry_char_t *end_p = path_p + strlen ((const char *) path_p); - - while (end_p > path_p) - { - if (end_p[-1] == '/' || end_p[-1] == '\\') - { - return (jerry_size_t) (end_p - path_p); - } - - end_p--; - } - - return 0; -} /* jerry_port_path_base */ - #endif /* defined(_WIN32) */ diff --git a/targets/os/nuttx/jerry-main.c b/targets/os/nuttx/jerry-main.c index 917aa53017..2076f32a37 100644 --- a/targets/os/nuttx/jerry-main.c +++ b/targets/os/nuttx/jerry-main.c @@ -212,7 +212,7 @@ jerry_main (int argc, char *argv[]) { for (i = 0; i < files_counter; i++) { - ret_value = jerryx_source_exec_script (file_names[i]); + ret_value = jerryx_source_exec_script (file_names[i], strlen (file_names[i])); if (jerry_value_is_exception (ret_value)) { ret_code = JERRY_STANDALONE_EXIT_CODE_FAIL;