Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement jerry_port_path_normalize in a more reliable way #5198

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading