Skip to content

Commit

Permalink
Attempting to make CF_strnlen scope-applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
jdfiguer authored and jdfiguer committed Jun 4, 2024
1 parent 12eff1c commit ee875ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
16 changes: 0 additions & 16 deletions fsw/src/cf_cfdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 20 additions & 2 deletions fsw/src/cf_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}
12 changes: 12 additions & 0 deletions fsw/src/cf_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

1 comment on commit ee875ae

@chillfig
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jphickey Can I get your advice on fsw organization?:

I want to use a currently static inline-defined helper function called CF_strnlen() at a different source file in CF at this new location: https://github.com/nasa/CF/blob/12eff1c97935942fb9aaa57f44c5ad50918b35b4/fsw/src/cf_utils.c#L202

What do you think is the best way to make that happen? My goal is to make accessible to both cf_utils.c and cf_cfdp.c

Please sign in to comment.