Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ibuf_add, ibuf_add_buf, ibuf_add_zero and ibuf_data for OpenBSD 7.3. #123

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,20 @@ check_function_exists(getopt HAVE_GETOPT)
if(HAVE_GETOPT)
add_definitions(-DHAVE_GETOPT)
endif()

check_function_exists(ibuf_add_buf HAVE_IBUF_ADD_BUF)
if(HAVE_IBUF_ADD_BUF)
add_definitions(-DHAVE_IBUF_ADD_BUF)
endif()
check_function_exists(ibuf_add_zero HAVE_IBUF_ADD_ZERO)
if(HAVE_IBUF_ADD_ZERO)
add_definitions(-DHAVE_IBUF_ADD_ZERO)
endif()
check_function_exists(ibuf_data HAVE_IBUF_DATA)
if(HAVE_IBUF_DATA)
add_definitions(-DHAVE_IBUF_DATA)
endif()

if(HAVE_VROUTE OR HAVE_VROUTE_NETLINK)
add_definitions(-DHAVE_VROUTE)
endif()
Expand Down
3 changes: 3 additions & 0 deletions compat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ endif()
if(NOT HAVE_VIS)
list(APPEND SRCS ${IKED_COMPAT}/vis.c)
endif()
if(NOT HAVE_IBUF_ADD_BUF OR NOT HAVE_IBUF_ADD_ZERO OR NOT HAVE_IBUF_DATA)
list(APPEND SRCS ${IKED_COMPAT}/ibuf-compat.c)
endif()

set(CFLAGS)
list(APPEND CFLAGS
Expand Down
72 changes: 72 additions & 0 deletions compat/ibuf-compat.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* $OpenBSD: imsg-buffer.c,v 1.16 2023/06/19 17:19:50 claudio Exp $ */

/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
*
* Permission to use, copy, modify, and 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.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

/* ibuf API functions added to OpenBSD's imsg-buffer.c in June 2023. */

#if !defined(HAVE_IBUF_ADD_BUF) || !defined(HAVE_IBUF_ADD_ZERO)
#include <sys/queue.h>

#include <string.h>
#include <imsg.h>
#endif /* !defined(HAVE_IBUF_ADD_BUF) || !defined(HAVE_IBUF_ADD_ZERO) */

#if !defined(HAVE_IBUF_ADD_BUF)
void *ibuf_reserve(struct ibuf *, size_t);

int
ibuf_add(struct ibuf *buf, const void *data, size_t len)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I wrap ibuf_add in it's own HAVE_IBUF_ADD ifdef?

{
void *b;

if ((b = ibuf_reserve(buf, len)) == NULL)
return (-1);

memcpy(b, data, len);
return (0);
}

int
ibuf_add_buf(struct ibuf *buf, const struct ibuf *from)
{
return ibuf_add(buf, from->buf, from->wpos);
}
#endif /* !defined(HAVE_IBUF_ADD_BUF) */

#if !defined(HAVE_IBUF_ADD_ZERO)
void *ibuf_reserve(struct ibuf *, size_t);

int
ibuf_add_zero(struct ibuf *buf, size_t len)
{
void *b;

if ((b = ibuf_reserve(buf, len)) == NULL)
return (-1);
return (0);
}
#endif /* !defined(HAVE_IBUF_ADD_ZERO) */

#if !defined(HAVE_IBUF_DATA)
void *ibuf_seek(struct ibuf *, size_t, size_t);

void *
ibuf_data(struct ibuf *buf)
{
return (ibuf_seek(buf, 0, 0));
}
#endif /* !defined(HAVE_IBUF_DATA) */
Loading