-
Notifications
You must be signed in to change notification settings - Fork 5
/
common.c
43 lines (35 loc) · 979 Bytes
/
common.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* common.c - Definitions of common routines
*
* Copyright © 2011 magical
*
* This file is part of spriterip; it is licensed under the GNU GPLv3
* and comes with NO WARRANTY. See rip.c for details.
*/
#include <stdlib.h> /* size_t, stderr, malloc */
#include <stdio.h> /* fprintf, vfprintf */
#include <stdarg.h> /* va_list, va_end, va_start */
#include <string.h> /* memset */
#include "common.h"
/******************************************************************************/
void
warn(const char *s, ...)
{
va_list va;
va_start(va, s);
vfprintf(stderr, s, va);
va_end(va);
fprintf(stderr, "\n");
}
/******************************************************************************/
struct buffer *
buffer_alloc(size_t size)
{
struct buffer *buffer = malloc(sizeof(*buffer) + size);
if (buffer != NULL) {
buffer->size = size;
memset(buffer->data, 0, buffer->size);
return buffer;
}
return NULL;
}
/* There is no buffer_free() - just use free(). */