libi3: change scalloc() signature to match calloc()

This commit is contained in:
shdown
2015-08-03 12:50:13 +03:00
parent 05fb909636
commit bc52fae15c
32 changed files with 80 additions and 81 deletions

View File

@ -23,7 +23,7 @@ void fake_configure_notify(xcb_connection_t *conn, xcb_rectangle_t r, xcb_window
/* Every X11 event is 32 bytes long. Therefore, XCB will copy 32 bytes.
* In order to properly initialize these bytes, we allocate 32 bytes even
* though we only need less for an xcb_configure_notify_event_t */
void *event = scalloc(32);
void *event = scalloc(32, 1);
xcb_configure_notify_event_t *generated_event = event;
generated_event->event = window;

View File

@ -34,7 +34,7 @@ char *resolve_tilde(const char *path) {
err(EXIT_FAILURE, "glob() failed");
} else {
head = globbuf.gl_pathv[0];
result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1);
result = scalloc(strlen(head) + (tail ? strlen(tail) : 0) + 1, 1);
strncpy(result, head, strlen(head));
if (tail)
strncat(result, tail, strlen(tail));

View File

@ -27,10 +27,10 @@ void *smalloc(size_t size) {
return result;
}
void *scalloc(size_t size) {
void *result = calloc(size, 1);
void *scalloc(size_t num, size_t size) {
void *result = calloc(num, size);
if (result == NULL)
err(EXIT_FAILURE, "calloc(%zd)", size);
err(EXIT_FAILURE, "calloc(%zd, %zd)", num, size);
return result;
}

View File

@ -33,7 +33,7 @@ struct _i3String {
*
*/
i3String *i3string_from_utf8(const char *from_utf8) {
i3String *str = scalloc(sizeof(i3String));
i3String *str = scalloc(1, sizeof(i3String));
/* Get the text */
str->utf8 = sstrdup(from_utf8);
@ -64,10 +64,10 @@ i3String *i3string_from_markup(const char *from_markup) {
*
*/
i3String *i3string_from_utf8_with_length(const char *from_utf8, size_t num_bytes) {
i3String *str = scalloc(sizeof(i3String));
i3String *str = scalloc(1, sizeof(i3String));
/* Copy the actual text to our i3String */
str->utf8 = scalloc(sizeof(char) * (num_bytes + 1));
str->utf8 = scalloc(num_bytes + 1, 1);
strncpy(str->utf8, from_utf8, num_bytes);
str->utf8[num_bytes] = '\0';
@ -97,12 +97,11 @@ i3String *i3string_from_markup_with_length(const char *from_markup, size_t num_b
*
*/
i3String *i3string_from_ucs2(const xcb_char2b_t *from_ucs2, size_t num_glyphs) {
i3String *str = scalloc(sizeof(i3String));
i3String *str = scalloc(1, sizeof(i3String));
/* Copy the actual text to our i3String */
size_t num_bytes = num_glyphs * sizeof(xcb_char2b_t);
str->ucs2 = scalloc(num_bytes);
memcpy(str->ucs2, from_ucs2, num_bytes);
str->ucs2 = scalloc(num_glyphs, sizeof(xcb_char2b_t));
memcpy(str->ucs2, from_ucs2, num_glyphs * sizeof(xcb_char2b_t));
/* Store the length */
str->num_glyphs = num_glyphs;

View File

@ -23,8 +23,8 @@ static iconv_t ucs2_conversion_descriptor = (iconv_t)-1;
*/
char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) {
/* Allocate the output buffer (UTF-8 is at most 4 bytes per glyph) */
size_t buffer_size = num_glyphs * 4 * sizeof(char) + 1;
char *buffer = scalloc(buffer_size);
size_t buffer_size = num_glyphs * 4 + 1;
char *buffer = scalloc(buffer_size, 1);
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;