void http_url_set_port(struct http_url *url, uint16_t port) { url->port_number = port; c_free(url->port); url->port = NULL; if (port > 0) c_asprintf(&url->port, "%u", port); }
int main (int argc, char *argv[]) { /* configure should already have checked that the locale is supported. */ if (setlocale (LC_ALL, "") == NULL) return 1; /* Test behaviour of snprintf() as a "control group". (We should be running in a locale where ',' is the decimal point.) */ { char s[16]; snprintf (s, sizeof s, "%#.0f", 1.0); if (!strcmp (s, "1.")) { /* Skip the test, since we're not in a useful locale for testing. */ return 77; } ASSERT (!strcmp (s, "1,")); } /* Test behaviour of c_asprintf() and c_vasprintf(). They should always use '.' as the decimal point. */ { int retval; char *s; retval = c_asprintf (&s, "%#.0f", 1.0); ASSERT (s != NULL); ASSERT (!strcmp (s, "1.")); ASSERT (retval == 2); free (s); retval = my_c_asprintf (&s, "%#.0f", 1.0); ASSERT (s != NULL); ASSERT (!strcmp (s, "1.")); ASSERT (retval == 2); free (s); } return 0; }
int sircc_highlighter_init_escape_sequences(struct sircc_highlighter *highlighter, const char *str, size_t sz) { const char *and; const char *ptr; size_t len; size_t nb_sequences; nb_sequences = sizeof(sircc_highlighting_sequences) / sizeof(sircc_highlighting_sequences[0]); ptr = str; len = sz; while (len > 0) { const char *sequence; size_t toklen; and = memchr(ptr, '&', len); if (and) { toklen = (size_t)(and - ptr); } else { toklen = len; } sequence = NULL; for (size_t i = 0; i < nb_sequences; i++) { const char *name; name = sircc_highlighting_sequences[i].name; if (toklen == strlen(name) && memcmp(ptr, name, toklen) == 0) { sequence = sircc_highlighting_sequences[i].sequence; break; } } if (!sequence) { char tmp[toklen + 1]; c_strlcpy(tmp, ptr, toklen + 1); c_set_error("unknown display attribute '%s'", tmp); return -1; } if (highlighter->sequence) { char *tmp; c_asprintf(&tmp, "%s%s", highlighter->sequence, sequence); c_free(highlighter->sequence); highlighter->sequence = tmp; } else { highlighter->sequence = strdup(sequence); } ptr += toklen; len -= toklen; if (and) { ptr++; len--; } } return 0; }