Skip to content

Commit 98b5404

Browse files
committed
feat(esp_linenoise): Add getters for out and in FD config members
1 parent c8707c8 commit 98b5404

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

esp_linenoise/include/esp_linenoise.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,26 @@ esp_err_t esp_linenoise_set_max_cmd_line_length(esp_linenoise_handle_t handle, s
307307
*/
308308
esp_err_t esp_linenoise_get_max_cmd_line_length(esp_linenoise_handle_t handle, size_t *max_cmd_line_length);
309309

310+
/**
311+
* @brief Return the output file descriptor used by esp_linenoise
312+
*
313+
* @param handle The esp_linenoise handle from which to get
314+
* the file descriptor
315+
* @param fd Return value containing the output file descriptor
316+
* @return ESP_OK on success, ESP_ERR_INVALID_ARG otherwise
317+
*/
318+
esp_err_t esp_linenoise_get_out_fd(esp_linenoise_handle_t handle, int *fd);
319+
320+
/**
321+
* @brief Return the input file descriptor used by esp_linenoise
322+
*
323+
* @param handle The esp_linenoise handle from which to get
324+
* the file descriptor
325+
* @param fd Return value containing the input file descriptor
326+
* @return ESP_OK on success, ESP_ERR_INVALID_ARG otherwise
327+
*/
328+
esp_err_t esp_linenoise_get_in_fd(esp_linenoise_handle_t handle, int *fd);
329+
310330
#ifdef __cplusplus
311331
}
312332
#endif

esp_linenoise/src/esp_linenoise.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,3 +1544,29 @@ esp_err_t esp_linenoise_get_max_cmd_line_length(esp_linenoise_handle_t handle, s
15441544
*max_cmd_line_length = ((esp_linenoise_instance_t *)handle)->config.max_cmd_line_length;
15451545
return ESP_OK;
15461546
}
1547+
1548+
inline __attribute__((always_inline))
1549+
esp_err_t esp_linenoise_get_out_fd(esp_linenoise_handle_t handle, int *fd)
1550+
{
1551+
ESP_LINENOISE_CHECK_INSTANCE(handle);
1552+
1553+
if (fd == NULL) {
1554+
return ESP_ERR_INVALID_ARG;
1555+
}
1556+
1557+
*fd = handle->config.out_fd;
1558+
return ESP_OK;
1559+
}
1560+
1561+
inline __attribute__((always_inline))
1562+
esp_err_t esp_linenoise_get_in_fd(esp_linenoise_handle_t handle, int *fd)
1563+
{
1564+
ESP_LINENOISE_CHECK_INSTANCE(handle);
1565+
1566+
if (fd == NULL) {
1567+
return ESP_ERR_INVALID_ARG;
1568+
}
1569+
1570+
*fd = handle->config.in_fd;
1571+
return ESP_OK;
1572+
}

esp_linenoise/test_apps/main/test_esp_linenoise_get_set.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,26 @@ TEST_CASE("save and load history to file", "[linenoise]")
121121

122122
TEST_ASSERT_EQUAL(ESP_OK, esp_linenoise_delete_instance(h));
123123
}
124+
125+
TEST_CASE("get out_fd and in_fd", "[linenoise]")
126+
{
127+
const int test_out_fd = 5;
128+
const int test_in_fd = 6;
129+
esp_linenoise_config_t config;
130+
esp_linenoise_get_instance_config_default(&config);
131+
config.out_fd = test_out_fd;
132+
config.in_fd = test_in_fd;
133+
134+
esp_linenoise_handle_t h;
135+
TEST_ASSERT_EQUAL(ESP_OK, esp_linenoise_create_instance(&config, &h));
136+
TEST_ASSERT_NOT_NULL(h);
137+
138+
int in_fd = -1;
139+
TEST_ASSERT_EQUAL(ESP_OK, esp_linenoise_get_in_fd(h, &in_fd));
140+
TEST_ASSERT_EQUAL(test_in_fd, in_fd);
141+
int out_fd = -1;
142+
TEST_ASSERT_EQUAL(ESP_OK, esp_linenoise_get_out_fd(h, &out_fd));
143+
TEST_ASSERT_EQUAL(test_out_fd, out_fd);
144+
145+
TEST_ASSERT_EQUAL(ESP_OK, esp_linenoise_delete_instance(h));
146+
}

0 commit comments

Comments
 (0)