diff --git a/fsw/public_inc/sample_lib.h b/fsw/public_inc/sample_lib.h index 571e843..b73e711 100644 --- a/fsw/public_inc/sample_lib.h +++ b/fsw/public_inc/sample_lib.h @@ -39,6 +39,27 @@ /************************************************************************* ** Exported Functions *************************************************************************/ + +/************************************************************************/ +/** \brief Library Initialization Function +** +** \par Description +** This function is required by CFE to initialize the library +** It should be specified in the cfe_es_startup.scr file as part +** of loading this library. It is not directly invoked by +** applications. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \returns +** \retstmt Returns #CFE_SUCCESS if successful \endcode +** \endreturns +** +*************************************************************************/ +int32 SAMPLE_LibInit(void); + + /************************************************************************/ /** \brief Sample Lib Function ** diff --git a/fsw/src/sample_lib.c b/fsw/src/sample_lib.c index b269706..129a1f5 100644 --- a/fsw/src/sample_lib.c +++ b/fsw/src/sample_lib.c @@ -31,15 +31,20 @@ #include "sample_lib.h" #include "sample_lib_version.h" +/* for "strncpy()" */ +#include + /************************************************************************* ** Macro Definitions *************************************************************************/ +#define SAMPLE_LIB_BUFFER_SIZE 16 + /************************************************************************* -** Private Function Prototypes +** Private Data Structures *************************************************************************/ -int32 SAMPLE_LibInit(void); +static char SAMPLE_Buffer[SAMPLE_LIB_BUFFER_SIZE]; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ @@ -49,8 +54,27 @@ int32 SAMPLE_LibInit(void); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 SAMPLE_LibInit(void) { + /* + * Call a C library function, like strcpy(), and test its result. + * + * This is primary for a unit test example, to have more than + * one code path to exercise. + * + * The specification for strncpy() indicates that it should return + * the pointer to the destination buffer, so it should be impossible + * for this to ever fail when linked with a compliant C library. + */ + if (strncpy(SAMPLE_Buffer, "SAMPLE DATA", sizeof(SAMPLE_Buffer)-1) != + SAMPLE_Buffer) + { + return CFE_STATUS_NOT_IMPLEMENTED; + } - OS_printf ("SAMPLE Lib Initialized. Version %d.%d.%d.%d", + /* ensure termination */ + SAMPLE_Buffer[sizeof(SAMPLE_Buffer)-1] = 0; + + + OS_printf ("SAMPLE Lib Initialized. Version %d.%d.%d.%d\n", SAMPLE_LIB_MAJOR_VERSION, SAMPLE_LIB_MINOR_VERSION, SAMPLE_LIB_REVISION, @@ -67,7 +91,7 @@ int32 SAMPLE_LibInit(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 SAMPLE_Function( void ) { - OS_printf ("SAMPLE_Function called\n"); + OS_printf ("SAMPLE_Function called, buffer=\'%s\'\n", SAMPLE_Buffer); return(CFE_SUCCESS);