openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/util-linux/2.33.2-r0/util-linux-2.33.2/sys-utils/dmesg.c
static void safe_fwrite(const char* buf, size_t size, int indent, FILE* out)
{
    size_t i;
#ifdef HAVE_WIDECHAR
    mbstate_t s;
    memset(&s, 0, sizeof(s));
#endif
    for (i = 0; i < size; i++)
    {
        const char* p = buf + i;
        int rc, hex = 0;
        size_t len;

#ifdef HAVE_WIDECHAR
        wchar_t wc;
        len = mbrtowc(&wc, p, size - i, &s);

        if (len == 0) /* L'\0' */
            return;

        if (len == (size_t)-1 || len == (size_t)-2)
        { /* invalid sequence */
            memset(&s, 0, sizeof(s));
            len = hex = 1;
        }
        else if (len > 1 && !iswprint(wc))
        { /* non-printable multibyte */
            hex = 1;
        }
        i += len - 1;
#else
        len = 1;
        if (!isprint((unsigned char)*p) &&
            !isspace((unsigned char)*p)) /* non-printable */
            hex = 1;
#endif
        if (hex)
            rc = fwrite_hex(p, len, out);
        else if (*p == '\n' && *(p + 1) && indent)
        {
            rc = fwrite(p, 1, len, out) != len;
            if (fprintf(out, "%*s", indent, "") != indent)
                rc |= 1;
        }
        else
            rc = fwrite(p, 1, len, out) != len;
        if (rc != 0)
        {
            if (errno != EPIPE)
                err(EXIT_FAILURE, _("write failed"));
            exit(EXIT_SUCCESS);
        }
    }
}
/*
 * Prints to 'out' and non-printable chars are replaced with \x<hex> sequences.
 */
Prints to 'out' and non-printable chars are replaced with \x sequences.
Prints to ' out ' and non - printable chars are replaced with \ x sequences .
static void safe_fwrite(const char* buf, size_t size, int indent, FILE* out)
{
    size_t i;
#ifdef HAVE_WIDECHAR
    mbstate_t s;
    memset(&s, 0, sizeof(s));
#endif
    for (i = 0; i < size; i++)
    {
        const char* p = buf + i;
        int rc, hex = 0;
        size_t len;
#ifdef HAVE_WIDECHAR
        wchar_t wc;
        len = mbrtowc(&wc, p, size - i, &s);
        if (len == 0) 
            return;
        if (len == (size_t)-1 || len == (size_t)-2)
        { 
            memset(&s, 0, sizeof(s));
            len = hex = 1;
        }
        else if (len > 1 && !iswprint(wc))
        { 
            hex = 1;
        }
        i += len - 1;
#else
        len = 1;
        if (!isprint((unsigned char)*p) &&
            !isspace((unsigned char)*p)) 
            hex = 1;
#endif
        if (hex)
            rc = fwrite_hex(p, len, out);
        else if (*p == '\n' && *(p + 1) && indent)
        {
            rc = fwrite(p, 1, len, out) != len;
            if (fprintf(out, "%*s", indent, "") != indent)
                rc |= 1;
        }
        else
            rc = fwrite(p, 1, len, out) != len;
        if (rc != 0)
        {
            if (errno != EPIPE)
                err(EXIT_FAILURE, _("write failed"));
            exit(EXIT_SUCCESS);
        }
    }
}
static void safe_fwrite ( const char * buf , size_t size , int indent , FILE * out ) { size_t i ; #ifdef HAVE_WIDECHAR mbstate_t s ; memset ( & s , 0 , sizeof ( s ) ) ; #endif for ( i = 0 ; i < size ; i ++ ) { const char * p = buf + i ; int rc , hex = 0 ; size_t len ; #ifdef HAVE_WIDECHAR wchar_t wc ; len = mbrtowc ( & wc , p , size - i , & s ) ; if ( len == 0 ) return ; if ( len == ( size_t ) -1 || len == ( size_t ) -2 ) { memset ( & s , 0 , sizeof ( s ) ) ; len = hex = 1 ; } else if ( len > 1 && ! iswprint ( wc ) ) { hex = 1 ; } i += len - 1 ; #else len = 1 ; if ( ! isprint ( ( unsigned char ) * p ) && ! isspace ( ( unsigned char ) * p ) ) hex = 1 ; #endif if ( hex ) rc = fwrite_hex ( p , len , out ) ; else if ( * p == ' \n ' && * ( p + 1 ) && indent ) { rc = fwrite ( p , 1 , len , out ) != len ; if ( fprintf ( out , " " , indent , " " ) != indent ) rc |= 1 ; } else rc = fwrite ( p , 1 , len , out ) != len ; if ( rc != 0 ) { if ( errno != EPIPE ) err ( EXIT_FAILURE , _ ( " " ) ) ; exit ( EXIT_SUCCESS ) ; } } }
Prints to 'out' and non-printable chars are replaced with \x<hex> sequences.
Prints to ' out ' and non - printable chars are replaced with \ x<hex > sequences .
/* L'\0' */ /* invalid sequence */ /* non-printable multibyte */ /* non-printable */