mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-08-25 11:05:52 +03:00
49 lines
1.0 KiB
C
49 lines
1.0 KiB
C
/*
|
|
* util.h - Common utility functions
|
|
*
|
|
* Written 2016 by Werner Almesberger
|
|
* Copyright 2016 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 <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
|
|
#define alloc_size(s) \
|
|
({ void *alloc_size_tmp = malloc(s); \
|
|
if (!alloc_size_tmp) { \
|
|
perror("malloc"); \
|
|
exit(1); \
|
|
} \
|
|
alloc_size_tmp; })
|
|
|
|
#define alloc_type(t) ((t *) alloc_size(sizeof(t)))
|
|
|
|
#define stralloc(s) \
|
|
({ char *stralloc_tmp = strdup(s); \
|
|
if (!stralloc_tmp) { \
|
|
perror("strdup"); \
|
|
exit(1); \
|
|
} \
|
|
stralloc_tmp; })
|
|
|
|
|
|
#define swap(a, b) \
|
|
({ typeof(a) _tmp = (a); a = (b); b = _tmp; })
|
|
|
|
|
|
#define unsupported(s) \
|
|
fprintf(stderr, __FILE__ ":%d: unsupported: " s "\n", __LINE__)
|
|
|
|
#endif /* !UTIL_H */
|