int my_strnequal(char *s1, char *s2, uint32_t max) { if(s1 == s2) return YES; if(s1 == NULL || s2 == NULL) return NO; uint32_t len1 = my_strnlen(s1, max); uint32_t len2 = my_strnlen(s2, max); if(len1 != len2) return NO; return (memcmp(s1, s2, len1) == 0); }
static void test( CYG_ADDRWORD data ) { static char x[32]; static char y[4]; int xret; int yret; int xstrlen; int ystrlen; // fill buffer to ensure that there are no zeros in the buffers memset(x, 0xFF, sizeof(x)); memset(y, 0xFF, sizeof(y)); // print into a buffer with sufficient size xret = snprintf(x, sizeof(x), "%d:%d:%d:%d", 1, 2, 3, 4); xstrlen = my_strnlen(x, sizeof(x)); // print into a buffer that is too small yret = snprintf(y, sizeof(y), "%d:%d:%d:%d", 1, 2, 3, 4); ystrlen = my_strnlen(y, sizeof(y)); CYG_TEST_PASS_FAIL(xret == xstrlen, "[buffer > strlen] return code"); #ifdef CYGIMP_LIBC_STDIO_C99_SNPRINTF // C99 compliant implementation returns the number of characters that // would have been written had size been sufficiently large, // not counting the terminating nul character CYG_TEST_PASS_FAIL(xret == yret, "[buffer < strlen] return code"); CYG_TEST_INFO("C99 compliant implementation of snprintf()"); #else // default eCos implementation returns number of bytes written into // the buffer without terminating nul character CYG_TEST_PASS_FAIL(yret == ystrlen, "[buffer < strlen] return code"); CYG_TEST_INFO("Default implementation of snprintf() (no C99 compliance)"); #endif CYG_TEST_FINISH("Finished tests from testcase " __FILE__ " for C library snprintf() function return values"); } // test()
// need better implementation static int is_binary_string(VALUE str) { const char *p; size_t len; p = RSTRING_PTR(str); len = RSTRING_LEN(str); if (my_strnlen(p, len) != len) { return 1; } return 0; }
/** print %s */ static void print_str(char **at, size_t * left, int *ret, char *s, int minw, int precision, int prgiven, int minus) { int w; /* with prec: no more than x characters from this string, stop at 0 */ if (prgiven) w = my_strnlen(s, precision); else w = (int)strlen(s); /* up to the nul */ if (w < minw && !minus) print_pad(at, left, ret, ' ', minw - w); spool_str(at, left, ret, s, w); if (w < minw && minus) print_pad(at, left, ret, ' ', minw - w); }
uint32_t my_strlen(const char *s) { return my_strnlen(s, UT_DEFAULT_MAX_STRLEN); }