refactor(string): remove thread-specific storage

This commit is contained in:
2025-12-03 07:59:49 +01:00
parent f15d94b02c
commit f8dcae213d
2 changed files with 69 additions and 70 deletions

View File

@@ -77,13 +77,41 @@ size_t string_cap(string_s *string);
* @brief Get a pointer to a null-terminated C-string.
*
* @param string String to read.
* @return Pointer to a thread-local buffer, or NULL on failure.
* @return Pointer to string->data.
*
* @note Valid until the next call in the same thread. Do NOT free the returned pointer.
* Do NOT call more than once this function in a print function.
* @note See string_lock().
*/
char *string_cstr(string_s *string);
/**
* @brief Create a heap-allocated copy of the string content.
*
* @param string String to copy.
* @return Newly allocated null-terminated buffer, or NULL on failure.
*
* @note The caller is responsible for freeing the returned buffer with free().
* See string_lock().
*/
char *string_copy(string_s *string);
/**
* @brief Lock the string for safe reading or writing.
*
* @param string String to lock.
* @return 0 on success, -1 on failure.
*
* @note Use this before calling string_cstr() if you want a stable pointer.
*/
int string_lock(string_s *string);
/**
* @brief Unlock a previously locked string.
*
* @param string String to unlock.
* @return 0 on success, -1 on failure.
*/
int string_unlock(string_s *string);
/**
* @brief Compare two strings.
*