Files
freebsd-src/libpkgconf/bsdstubs.c
T
Pierre Pronchery fe9da42ef1 Vendor import of pkgconf 3.0.9
Obtained from https://github.com/pkgconf/pkgconf/archive/refs/tags/pkgconf-3.0.9.tar.gz

SHA1: a390f016a7a5ff419c9eef9e2b2c01fe86c11971  -
SHA256: 32310a33bb97425ebc0707cb5af59f9dc05d10282dcd4db628a45ed904993dc6  -
SHA512: 30776d31f860910286b96fbf60a19b5a6d1e73cb6a1077a019d763ae6e5ed1e8d81bc3649978c83f40e5e90ae779f7e530c513b700c8e73bb6399883dd6ef7ab  -

Sponsored by:	The FreeBSD Foundation
2026-11-02 00:28:01 +01:00

108 lines
2.2 KiB
C

/*
* SPDX-License-Identifier: pkgconf
*
* Copyright (c) 2012 Ariadne Conill <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* This software is provided 'as is' and without any warranty, express or
* implied. In no event shall the authors be liable for any damages arising
* from the use of this software.
*/
#include <libpkgconf/stdinc.h>
#include <libpkgconf/bsdstubs.h>
#include <libpkgconf/config.h>
#if HAVE_DECL_STRNDUP
# define pkgconf_strndup_impl strndup
#else
/*
* Creates a memory buffer and copies at most 'len' characters to it.
* If 'len' is less than the length of the source string, truncation occurred.
*/
static inline char *
pkgconf_strndup_impl(const char *src, size_t len)
{
const char *end = memchr(src, '\0', len);
size_t n = end != NULL ? (size_t)(end - src) : len;
char *out = malloc(n + 1);
if (out == NULL)
return NULL;
memcpy(out, src, n);
out[n] = '\0';
return out;
}
#endif
#if HAVE_DECL_PLEDGE
# define pkgconf_pledge_impl pledge
#else
static inline int
pkgconf_pledge_impl(const char *promises, const char *execpromises)
{
(void) promises;
(void) execpromises;
return 0;
}
#endif
#if HAVE_DECL_UNVEIL
# define pkgconf_unveil_impl unveil
#else
static inline int
pkgconf_unveil_impl(const char *path, const char *permissions)
{
(void) path;
(void) permissions;
return 0;
}
#endif
#if HAVE_DECL_REALLOCARRAY
# define pkgconf_reallocarray_impl reallocarray
#else
static inline void *
pkgconf_reallocarray_impl(void *ptr, size_t m, size_t n)
{
if (n && m > -1 / n)
{
errno = ENOMEM;
return 0;
}
return realloc(ptr, m * n);
}
#endif
char *
pkgconf_strndup(const char *src, size_t len)
{
return pkgconf_strndup_impl(src, len);
}
void *
pkgconf_reallocarray(void *ptr, size_t m, size_t n)
{
return pkgconf_reallocarray_impl(ptr, m, n);
}
int
pkgconf_pledge(const char *promises, const char *execpromises)
{
return pkgconf_pledge_impl(promises, execpromises);
}
int
pkgconf_unveil(const char *path, const char *permissions)
{
return pkgconf_unveil_impl(path, permissions);
}