Skip to content

Commit

Permalink
Implement jerry_port_path_normalize in a more reliable way
Browse files Browse the repository at this point in the history
Replace jerry_port_path_normalize,jerry_port_path_free,jerry_port_path_base with jerry_port_path_style,jerry_port_get_cwd

Partially fixes jerryscript-project#4979
Closes: jerryscript-project#4983

JerryScript-DCO-1.0-Signed-off-by: Yonggang Luo [email protected]
  • Loading branch information
lygstate committed Dec 17, 2024
1 parent d2d30df commit ca387ba
Show file tree
Hide file tree
Showing 10 changed files with 824 additions and 165 deletions.
59 changes: 25 additions & 34 deletions docs/05.PORT-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ void jerry_port_init (void);
void jerry_port_fatal (jerry_fatal_code_t code);
```

The path style of the OS

```c
typedef enum
{
JERRY_STYLE_WINDOWS,
JERRY_STYLE_UNIX,
} jerry_path_style_t;
```

Error codes

```c
Expand Down Expand Up @@ -172,52 +182,33 @@ void jerry_port_line_free (jerry_char_t *buffer_p);

## Filesystem

```
/**
* Canonicalize a file path.
*
* If possible, the implementation should resolve symbolic links and other directory references found in the input path,
* and create a fully canonicalized file path as the result.
*
* The function may return with NULL in case an error is encountered, in which case the calling operation will not
* proceed.
*
* The implementation should allocate storage for the result path as necessary. Non-NULL return values will be passed
* to `jerry_port_path_free` when the result is no longer needed by the caller, which can be used to finalize
* dynamically allocated buffers.
*
* NOTE: The implementation must not return directly with the input, as the input buffer is released after the call.
*
* @param path_p: zero-terminated string containing the input path
* @param path_size: size of the input path string in bytes, excluding terminating zero
*
* @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);
```

```c
/**
* Free a path buffer returned by jerry_port_path_normalize.
* Get the path style of the current OS
*
* @param path_p: the path buffer to free
* @return path style
*/
void jerry_port_path_free (jerry_char_t *path_p);
jerry_path_style_t jerry_port_path_style (void);
```
```c
/**
* Get the offset of the basename component in the input path.
* Get the cwd, the output string will be zero-terminated
*
* 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 buffer_p: the buffer to storage the cwd
* @param buffer_size: the `buffer_p` buffer size, including '\0` terminator
*
* @param path_p: input zero-terminated path string
* @note
* - cwd: current working directory
*
* @return offset of the basename component in the input path
* @return The length of cwd, excluding '\0' terminator
* - When buffer_p is `NULL` and get cwd succeed return length of cwd
* - When buffer_p is `NULL` and get cwd failed return 0
* - When buffer_p is not `NULL` and the `buffer_size - 1` just equal to
* length of cwd; and get cwd succeed return `buffer_size - 1`.
* - Otherwise means get cwd failed and return 0
*/
jerry_size_t jerry_port_path_base (const jerry_char_t *path_p);
jerry_size_t jerry_port_get_cwd (jerry_char_t *buffer_p, jerry_size_t buffer_size);
```

```c
Expand Down
Loading

0 comments on commit ca387ba

Please sign in to comment.