use my atrb header, since it's more platform-agnostic

This commit is contained in:
2025-06-12 10:51:00 +02:00
parent cad49f2912
commit 5e6d7d22e0
3 changed files with 9 additions and 4 deletions

View File

@@ -10,6 +10,7 @@
#define atrb_pure __attribute__((pure)) #define atrb_pure __attribute__((pure))
#define atrb_const __attribute__((const)) #define atrb_const __attribute__((const))
#define atrb_noreturn __attribute__((noreturn)) #define atrb_noreturn __attribute__((noreturn))
#define atrb_malloc __attribute__((malloc))
#define atrb_format(...) __attribute__((format(__VA_ARGS__))) #define atrb_format(...) __attribute__((format(__VA_ARGS__)))
#define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__))) #define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
@@ -23,6 +24,7 @@
#define atrb_pure #define atrb_pure
#define atrb_const #define atrb_const
#define atrb_noreturn #define atrb_noreturn
#define atrb_malloc
#define atrb_format() #define atrb_format()
#define atrb_nonnull() #define atrb_nonnull()
#endif #endif

View File

@@ -5,7 +5,8 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/cdefs.h>
#include "atrb.h"
int conf_procbuf(char const* restrict buf, size_t buflen, struct conf_entry const* opts, size_t optc) { int conf_procbuf(char const* restrict buf, size_t buflen, struct conf_entry const* opts, size_t optc) {
enum { enum {
@@ -70,7 +71,7 @@ int conf_procbuf(char const* restrict buf, size_t buflen, struct conf_entry cons
} }
/* utility function for conf_getpat to concatenate 3 strings, where we already know the size */ /* utility function for conf_getpat to concatenate 3 strings, where we already know the size */
__nonnull((1, 3)) static inline char* conf_getpat_concat(char const* restrict s1, char const* restrict s2, char const* restrict s3, size_t s1len, size_t s2len, size_t s3len) { atrb_nonnull(1, 3) static inline char* conf_getpat_concat(char const* restrict s1, char const* restrict s2, char const* restrict s3, size_t s1len, size_t s2len, size_t s3len) {
char *buf, *ptr; char *buf, *ptr;
// allocate enough data for all three to the buffer // allocate enough data for all three to the buffer

View File

@@ -2,7 +2,9 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <sys/cdefs.h> #include <stdlib.h>
#include "atrb.h"
/* defines the primitive types available in the config file */ /* defines the primitive types available in the config file */
enum config_primitive { enum config_primitive {
@@ -43,4 +45,4 @@ int conf_procbuf(char const*, size_t, struct conf_entry const*, size_t);
* - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned. * - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned.
* - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned. * - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned.
* !! A malloc'd null-terminated string is returned !! */ * !! A malloc'd null-terminated string is returned !! */
__attribute_malloc__ __attribute_nonnull__((1)) char* conf_getpat(char const*); atrb_malloc atrb_nonnull(1) char* conf_getpat(char const*);