sci/include/util.h

45 lines
1.4 KiB
C
Raw Permalink Normal View History

2024-08-19 19:06:49 +02:00
/**
* sci - a simple ci system
Copyright (C) 2024 Asger Gitz-Johansen
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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2024-08-02 19:11:12 +02:00
#ifndef SCI_UTIL_H
#define SCI_UTIL_H
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sys/errno.h>
#include <unistd.h>
#define ASSERT_SYSCALL_SUCCESS(fd) \
do { \
if ((fd) == -1) { \
fprintf(stderr, "Assertion failed: %s, errno: %d, error: %s\n", #fd, errno, strerror(errno)); \
assert(fd != -1); \
} \
} while (0)
#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0]))
// remove whitespace characters on both ends of the string.
// Retuirns a new string that you must free.
char* trim(const char* const str);
typedef void(*line_handler)(const char*);
void per_line(const char* file, line_handler handler);
2024-08-02 19:11:12 +02:00
char* join(const char* a, const char* b);
2024-08-02 19:11:12 +02:00
#endif