Skip to content

Commit 3d79a83

Browse files
committed
Implement jerry_port_path_normalize in a more reliable way
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]
1 parent aa7861d commit 3d79a83

File tree

10 files changed

+739
-214
lines changed

10 files changed

+739
-214
lines changed

docs/05.PORT-API.md

+15-34
Original file line numberDiff line numberDiff line change
@@ -163,52 +163,33 @@ void jerry_port_line_free (jerry_char_t *buffer_p);
163163

164164
## Filesystem
165165

166-
```
167-
/**
168-
* Canonicalize a file path.
169-
*
170-
* If possible, the implementation should resolve symbolic links and other directory references found in the input path,
171-
* and create a fully canonicalized file path as the result.
172-
*
173-
* The function may return with NULL in case an error is encountered, in which case the calling operation will not
174-
* proceed.
175-
*
176-
* The implementation should allocate storage for the result path as necessary. Non-NULL return values will be passed
177-
* to `jerry_port_path_free` when the result is no longer needed by the caller, which can be used to finalize
178-
* dynamically allocated buffers.
179-
*
180-
* NOTE: The implementation must not return directly with the input, as the input buffer is released after the call.
181-
*
182-
* @param path_p: zero-terminated string containing the input path
183-
* @param path_size: size of the input path string in bytes, excluding terminating zero
184-
*
185-
* @return buffer with the normalized path if the operation is successful,
186-
* NULL otherwise
187-
*/
188-
jerry_char_t *jerry_port_path_normalize (const jerry_char_t *path_p, jerry_size_t path_size);
189-
```
190-
191166
```c
192167
/**
193-
* Free a path buffer returned by jerry_port_path_normalize.
168+
* Get the path style of the current OS
194169
*
195-
* @param path_p: the path buffer to free
170+
* @return path style
196171
*/
197-
void jerry_port_path_free (jerry_char_t *path_p);
172+
jerry_path_style_t jerry_port_path_style (void);
198173
```
199174
200175
```c
201176
/**
202-
* Get the offset of the basename component in the input path.
177+
* Get the cwd, the output string will be zero-terminated
203178
*
204-
* The implementation should return the offset of the first character after the last path separator found in the path.
205-
* This is used by the caller to split the path into a directory name and a file name.
179+
* @param buffer_p: the buffer to storage the cwd
180+
* @param buffer_size: the `buffer_p` buffer size, including '\0` terminator
206181
*
207-
* @param path_p: input zero-terminated path string
182+
* @note
183+
* - cwd: current working directory
208184
*
209-
* @return offset of the basename component in the input path
185+
* @return The length of cwd, excluding '\0' terminator
186+
* - When buffer_p is `NULL` and get cwd succeed return length of cwd
187+
* - When buffer_p is `NULL` and get cwd failed return 0
188+
* - When buffer_p is not `NULL` and the `buffer_size - 1` just equal to
189+
* length of cwd; and get cwd succeed return `buffer_size - 1`.
190+
* - Otherwise means get cwd failed and return 0
210191
*/
211-
jerry_size_t jerry_port_path_base (const jerry_char_t *path_p);
192+
jerry_size_t jerry_port_get_cwd (jerry_char_t *buffer_p, jerry_size_t buffer_size);
212193
```
213194

214195
```c

0 commit comments

Comments
 (0)