mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-22 10:10:54 +00:00
Add strbuf_helpers.[ch]
Functions to help assemble strbuf contents.
This commit is contained in:
parent
63d1792863
commit
c7488de510
@ -21,6 +21,7 @@ SERVALD_SRC_FILES = \
|
|||||||
serval-dna/net.c \
|
serval-dna/net.c \
|
||||||
serval-dna/mkdir.c \
|
serval-dna/mkdir.c \
|
||||||
serval-dna/strbuf.c \
|
serval-dna/strbuf.c \
|
||||||
|
serval-dna/strbuf_helpers.c \
|
||||||
serval-dna/gateway.c \
|
serval-dna/gateway.c \
|
||||||
serval-dna/overlay.c \
|
serval-dna/overlay.c \
|
||||||
serval-dna/overlay_broadcast.c \
|
serval-dna/overlay_broadcast.c \
|
||||||
|
@ -10,6 +10,7 @@ SRCS= main.c \
|
|||||||
net.c \
|
net.c \
|
||||||
mkdir.c \
|
mkdir.c \
|
||||||
strbuf.c \
|
strbuf.c \
|
||||||
|
strbuf_helpers.c \
|
||||||
dna_identity.c \
|
dna_identity.c \
|
||||||
encode.c \
|
encode.c \
|
||||||
fifo.c \
|
fifo.c \
|
||||||
@ -70,6 +71,7 @@ HDRS= fifo.h \
|
|||||||
rhizome.h \
|
rhizome.h \
|
||||||
serval.h \
|
serval.h \
|
||||||
strbuf.h \
|
strbuf.h \
|
||||||
|
strbuf_helpers.h \
|
||||||
sha2.h \
|
sha2.h \
|
||||||
sqlite-amalgamation-3070900/sqlite3.h
|
sqlite-amalgamation-3070900/sqlite3.h
|
||||||
|
|
||||||
|
63
strbuf_helpers.c
Normal file
63
strbuf_helpers.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
Serval string buffer helper functions.
|
||||||
|
Copyright (C) 2012 The Serval Project
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "strbuf_helpers.h"
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
|
strbuf strbuf_append_poll_events(strbuf sb, short events)
|
||||||
|
{
|
||||||
|
static struct { short flags; const char *name; } symbols[] = {
|
||||||
|
{ POLLIN, "IN" },
|
||||||
|
{ POLLPRI, "PRI" },
|
||||||
|
{ POLLOUT, "OUT" },
|
||||||
|
{ POLLERR, "ERR" },
|
||||||
|
{ POLLHUP, "HUP" },
|
||||||
|
{ POLLNVAL, "NVAL" },
|
||||||
|
{ POLLRDNORM, "RDNORM" },
|
||||||
|
{ POLLRDBAND, "RDBAND" },
|
||||||
|
#ifdef POLLWRNORM
|
||||||
|
{ POLLWRNORM, "WRNORM" },
|
||||||
|
#endif
|
||||||
|
#ifdef POLLWRBAND
|
||||||
|
{ POLLWRBAND, "WRBAND" },
|
||||||
|
#endif
|
||||||
|
#ifdef POLLMSG
|
||||||
|
{ POLLMSG, "MSG" },
|
||||||
|
#endif
|
||||||
|
#ifdef POLLREMOVE
|
||||||
|
{ POLLREMOVE, "REMOVE" },
|
||||||
|
#endif
|
||||||
|
#ifdef POLLRDHUP
|
||||||
|
{ POLLRDHUP, "RDHUP" },
|
||||||
|
#endif
|
||||||
|
{ 0, NULL }
|
||||||
|
}, *sp;
|
||||||
|
int n = 0;
|
||||||
|
for (sp = symbols; sp->name; ++sp) {
|
||||||
|
if (events & sp->flags) {
|
||||||
|
if (n)
|
||||||
|
strbuf_putc(sb, '|');
|
||||||
|
strbuf_puts(sb, sp->name);
|
||||||
|
++n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!n)
|
||||||
|
strbuf_putc(sb, '0');
|
||||||
|
return sb;
|
||||||
|
}
|
30
strbuf_helpers.h
Normal file
30
strbuf_helpers.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
Serval string buffer helper functions.
|
||||||
|
Copyright (C) 2012 The Serval Project
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
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, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __STRBUF_HELPERS_H__
|
||||||
|
#define __STRBUF_HELPERS_H__
|
||||||
|
|
||||||
|
#include "strbuf.h"
|
||||||
|
|
||||||
|
/* Append a symbolic representation of the poll(2) event flags.
|
||||||
|
* @author Andrew Bettison <andrew@servalproject.com>
|
||||||
|
*/
|
||||||
|
strbuf strbuf_append_poll_events(strbuf sb, short events);
|
||||||
|
|
||||||
|
#endif //__STRBUF_HELPERS_H__
|
Loading…
x
Reference in New Issue
Block a user