mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-25 17:05:20 +02:00
tools/libtxt/: move alloc_sprintf from font.c to util.h, for later sharing
This commit is contained in:
parent
8cfe660a2e
commit
d33449e128
@ -13,7 +13,8 @@
|
||||
|
||||
LIB = libtxt.a
|
||||
|
||||
CFLAGS = -g -Wall
|
||||
# _GNU_SOURCE for vasprintf
|
||||
CFLAGS = -g -Wall -D_GNU_SOURCE
|
||||
|
||||
OBJS = edit.o font.o
|
||||
|
||||
|
@ -11,14 +11,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#define _GNU_SOURCE /* for vasprintf */
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "libtxt.h"
|
||||
|
||||
|
||||
@ -45,28 +43,6 @@ struct font {
|
||||
};
|
||||
|
||||
|
||||
/* ----- Helper functions -------------------------------------------------- */
|
||||
|
||||
|
||||
static const char *alloc_sprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *tmp, *res;
|
||||
int n;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vasprintf(&tmp, fmt, ap);
|
||||
va_end(ap);
|
||||
if (n < 0)
|
||||
abort();
|
||||
res = malloc(n+1);
|
||||
if (!res)
|
||||
abort();
|
||||
memcpy(res, tmp, n+1);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/* ----- XBM image --------------------------------------------------------- */
|
||||
|
||||
|
||||
|
40
tools/libtxt/util.h
Normal file
40
tools/libtxt/util.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* tools/libtxt/util.h - Utility functions
|
||||
*
|
||||
* Written 2012 by Werner Almesberger
|
||||
* Copyright 2012 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static const char *alloc_sprintf(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *tmp, *res;
|
||||
int n;
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = vasprintf(&tmp, fmt, ap);
|
||||
va_end(ap);
|
||||
if (n < 0)
|
||||
abort();
|
||||
res = malloc(n+1);
|
||||
if (!res)
|
||||
abort();
|
||||
memcpy(res, tmp, n+1);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif /* !UTIL_H */
|
Loading…
Reference in New Issue
Block a user