Beispiel #1
0
void mmocdbg_print_message
(
     
     const char *string,
       /* Format in which string needs to be printed */
     ...
)
{
  AEEVaList   arg_ptr;
  char        msg_str[ MMOC_MAX_STRING_LENGTH];

  /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /* Clear the string buffer 
  */
  memset (msg_str, 0, sizeof(msg_str));

  /*lint -save -e64 -e718 -e746 -e63 */
  AEEVA_START( arg_ptr, string );
  /*lint -restore */

  /*  Writing max of MMOC_MAX_STRING_LENGTH-1 characters only, 
  **  so the end null character stays untouched.
  */  
  (void)std_vstrlprintf (msg_str, MMOC_MAX_STRING_LENGTH - 1, 
                                                        string, arg_ptr);
  AEEVA_END( arg_ptr );

  MSG_SPRINTF_1(MSG_SSID_DFLT, MSG_LVL_HIGH, "=MMOC= %s", msg_str);

} /* mmocdbg_print_message() */
/**
  @brief: This function is used to Aggregate the formated buffer, this
  also check the overflow condition and adds the overflow message
  to the end of the log Dump buffer reserved of MAX_OVERFLOW_MSG size.
  @param: tpAniSirGlobal pMac
  @param: char *pBuf
  @param: variable arguments...
  @return: Returns the number of bytes added to the buffer.
  Returns 0 incase of overflow.

  @note: Currently in windows we do not print the Aggregated buffer as there
  is a limitation on the number of bytes that can be displayed by DbgPrint
  So we print the buffer immediately and we would also aggregate where
  the TestDbg might use this buffer to print out at the application level.
  */
int log_sprintf(tpAniSirGlobal pMac, char *pBuf, char *fmt, ...)
{
    tANI_S32 ret = 0;
#ifdef WLAN_DEBUG

#if defined(ANI_OS_TYPE_AMSS)
    AEEVaList args;
    AEEVA_START(args, fmt);
#else
    va_list args;
    va_start(args, fmt);
#endif

    if (pMac->gCurrentLogSize >= MAX_LOGDUMP_SIZE)
        return 0;

#if defined (ANI_OS_TYPE_WINDOWS)
    ret = _vsnprintf(pBuf, (MAX_LOGDUMP_SIZE - pMac->gCurrentLogSize), fmt, args);
#elif (defined (ANI_OS_TYPE_LINUX) || defined (ANI_OS_TYPE_ANDROID))
    ret = vsnprintf(pBuf, (MAX_LOGDUMP_SIZE - pMac->gCurrentLogSize), fmt, args);
#elif defined (ANI_OS_TYPE_OSX)
    ret = vsnprintf(pBuf, (MAX_LOGDUMP_SIZE - pMac->gCurrentLogSize), fmt, args);
    /* BSD kernel has a bug that vsnprintf() always return 0.
     * See bsd/kern/subr_prf.c 
     * Need to verify ...
     */
    if (ret >= 0)
        ret = strlen(pBuf);
#elif defined (ANI_OS_TYPE_AMSS)
    ret = std_vstrlprintf(pBuf, (MAX_LOGDUMP_SIZE - pMac->gCurrentLogSize), fmt, args);
#endif

#if defined(ANI_OS_TYPE_AMSS)
    AEEVA_END(args);
#else
    va_end(args);
#endif

    /* If an output error is encountered, a negative value is returned by vsnprintf */
    if (ret < 0)
        return 0;


    if ((tANI_U32) ret > (MAX_LOGDUMP_SIZE - pMac->gCurrentLogSize)) {
        pBuf += (MAX_LOGDUMP_SIZE - pMac->gCurrentLogSize);
        pMac->gCurrentLogSize = MAX_LOGDUMP_SIZE;

#if defined (ANI_OS_TYPE_WINDOWS)
        ret = _snprintf(pBuf, MAX_OVERFLOW_MSG, "\n-> ***********"
                "\nOutput Exceeded the Buffer Size, message truncated!!\n<- ***********\n");
#elif (defined (ANI_OS_TYPE_LINUX) || defined (ANI_OS_TYPE_ANDROID))
        ret = snprintf(pBuf, MAX_OVERFLOW_MSG, "\n-> ***********"
                "\nOutput Exceeded the Buffer Size, message truncated!!\n<- ***********\n");
#elif defined (ANI_OS_TYPE_OSX)
        ret = snprintf(pBuf, MAX_OVERFLOW_MSG, "\n-> ***********"
                "\nOutput Exceeded the Buffer Size, message truncated!!\n<- ***********\n");
        /* BSD kernel has a bug that snprintf() always return 0.
         * See bsd/kern/subr_prf.c 
         * but NEED TO VERIFY ...
         */
        if (ret >= 0)
            ret = strlen(pBuf);
#elif defined (ANI_OS_TYPE_AMSS)
        ret = snprintf(pBuf, MAX_OVERFLOW_MSG, "\n-> ***********"
                "\nOutput Exceeded the Buffer Size, message truncated!!\n<- ***********\n");
#endif
        /* If an output error is encountered, a negative value is returned by snprintf */
        if (ret < 0)
            return 0;

        if (ret > MAX_OVERFLOW_MSG)
            ret = MAX_OVERFLOW_MSG;
    }

    pMac->gCurrentLogSize += ret;


#if defined (ANI_OS_TYPE_WINDOWS)
    //DbgPrint("%s", pBuf);
    sysLog(pMac, LOGE, FL("%s"), pBuf);
#endif
#endif //for #ifdef WLAN_DEBUG
    return ret;
}