From ee875ae5a38e7cc12db357d1c2786cbcaef9be09 Mon Sep 17 00:00:00 2001 From: jdfiguer Date: Tue, 4 Jun 2024 16:34:13 -0400 Subject: [PATCH] Attempting to make CF_strnlen scope-applicable --- fsw/src/cf_cfdp.c | 16 ---------------- fsw/src/cf_utils.c | 22 ++++++++++++++++++++-- fsw/src/cf_utils.h | 12 ++++++++++++ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/fsw/src/cf_cfdp.c b/fsw/src/cf_cfdp.c index c79fa8d3..7e4c0376 100644 --- a/fsw/src/cf_cfdp.c +++ b/fsw/src/cf_cfdp.c @@ -299,22 +299,6 @@ CF_Logical_PduBuffer_t *CF_CFDP_ConstructPduHeader(const CF_Transaction_t *txn, return ph; } -/*---------------------------------------------------------------- - * - * Internal helper routine only, not part of API. - * - *-----------------------------------------------------------------*/ -static inline size_t CF_strnlen(const char *str, size_t maxlen) -{ - const char *end = memchr(str, 0, maxlen); - if (end != NULL) - { - /* actual length of string is difference */ - maxlen = end - str; - } - return maxlen; -} - /*---------------------------------------------------------------- * * Application-scope internal function diff --git a/fsw/src/cf_utils.c b/fsw/src/cf_utils.c index 4b35c9b6..715dd4de 100644 --- a/fsw/src/cf_utils.c +++ b/fsw/src/cf_utils.c @@ -196,8 +196,7 @@ CFE_Status_t CF_WriteHistoryEntryToFile(osal_id_t fd, const CF_History_t *histor snprintf(linebuf, sizeof(linebuf), "DST: %s\n", history->fnames.dst_filename); break; } - - len = strlen(linebuf); + len = CF_strnlen(linebuf, (CF_FILENAME_MAX_LEN * 2) + 128); ret = CF_WrappedWrite(fd, linebuf, len); if (ret != len) { @@ -588,3 +587,22 @@ CF_TxnStatus_t CF_TxnStatus_From_ConditionCode(CF_CFDP_ConditionCode_t cc) /* All CFDP CC values directly correspond to a Transaction Status of the same numeric value */ return (CF_TxnStatus_t)cc; } + +/*---------------------------------------------------------------- + * + * Function: CF_strnlen + * + * Application-scope internal function + * See description in cf_utils.h for argument/return detail + * + *-----------------------------------------------------------------*/ +size_t CF_strnlen(const char *str, size_t maxlen) +{ + const char *end = memchr(str, 0, maxlen); + if (end != NULL) + { + /* actual length of string is difference */ + maxlen = end - str; + } + return maxlen; +} \ No newline at end of file diff --git a/fsw/src/cf_utils.h b/fsw/src/cf_utils.h index fd839ce0..2df0aa0e 100644 --- a/fsw/src/cf_utils.h +++ b/fsw/src/cf_utils.h @@ -518,4 +518,16 @@ CF_TxnStatus_t CF_TxnStatus_From_ConditionCode(CF_CFDP_ConditionCode_t cc); */ bool CF_TxnStatus_IsError(CF_TxnStatus_t txn_stat); +/************************************************************************/ +/** @brief Converts a CFDP condition code to an internal transaction status + * + * @par Assumptions, External Events, and Notes: + * None + * + * @param cc CFDP condition code + * + * @returns Transaction status code + */ +size_t CF_strnlen(const char *str, size_t maxlen); + #endif /* !CF_UTILS_H */