ATF_TC_BODY(sdl_print, tc) { char buf[1024]; char res[1024]; int r, e; size_t l = sizeof(buf); struct sockaddr_dl sdl; memset(&sdl, 0, sizeof(sdl)); for (size_t i = 0; i < __arraycount(tst); i++) { memcpy(&sdl.sdl_addr, &tst[i].ia, sizeof(sdl.sdl_addr)); sdl.sdl_index = (uint16_t)i; r = sdl_print(buf, l, &sdl); e = snprintf(res, l, "[%s]:%zu", tst[i].str, i); ATF_REQUIRE_STREQ(buf, res); ATF_REQUIRE_EQ(r, e); } l = 8; for (size_t i = 0; i < __arraycount(tst); i++) { memcpy(&sdl.sdl_addr, &tst[i].ia, sizeof(sdl.sdl_addr)); sdl.sdl_index = (uint16_t)i; r = sdl_print(buf, l, &sdl); e = snprintf(res, l, "[%s]:%zu", tst[i].str, i); ATF_REQUIRE_STREQ(buf, res); ATF_REQUIRE_EQ(r, e); } }
int sockaddr_format(const struct sockaddr *sa, char *buf, size_t len) { size_t plen = 0; if (sa == NULL) return strlcpy(buf, "(null)", len); switch (sa->sa_family) { case AF_LOCAL: plen = strlcpy(buf, "unix: ", len); break; case AF_INET: plen = strlcpy(buf, "inet: ", len); break; case AF_INET6: plen = strlcpy(buf, "inet6: ", len); break; case AF_LINK: plen = strlcpy(buf, "link: ", len); break; case AF_APPLETALK: plen = strlcpy(buf, "atalk: ", len); break; default: return snprintf(buf, len, "(unknown socket family %d)", (int)sa->sa_family); } buf += plen; if (plen > len) len = 0; else len -= plen; switch (sa->sa_family) { case AF_LOCAL: return sun_print(buf, len, sa); case AF_INET: return sin_print(buf, len, sa); case AF_INET6: return sin6_print(buf, len, sa); case AF_LINK: return sdl_print(buf, len, sa); case AF_APPLETALK: return sat_print(buf, len, sa); default: panic("bad family %hhu", sa->sa_family); } }
void sdl_print_center_x(LBXAnimation_t * anim,int x, int y, const char * string) { size_t i; int index; int w=0; for(i=0; i<strlen(string); i++) { if(string[i] < 32 || string[i] > 32+LBX_FONT_CHAR_NUM) { continue; } index = string[i]-32; w+=anim[index].w; } sdl_print(anim,x-(w/2),y,string); }