]> git.proxmox.com Git - mirror_frr.git/blobdiff - nhrpd/zbuf.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / nhrpd / zbuf.c
index 97962b9ab8af14fa07b875cddf15ef4c5409f412..c662295083e79063f814c14bfeecdde45fd03880 100644 (file)
@@ -7,7 +7,10 @@
  * (at your option) any later version.
  */
 
-#define _GNU_SOURCE
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
@@ -25,10 +28,8 @@ struct zbuf *zbuf_alloc(size_t size)
        struct zbuf *zb;
 
        zb = XMALLOC(MTYPE_ZBUF_DATA, sizeof(*zb) + size);
-       if (!zb)
-               return NULL;
 
-       zbuf_init(zb, zb+1, size, 0);
+       zbuf_init(zb, zb + 1, size, 0);
        zb->allocated = 1;
 
        return zb;
@@ -36,7 +37,7 @@ struct zbuf *zbuf_alloc(size_t size)
 
 void zbuf_init(struct zbuf *zb, void *buf, size_t len, size_t datalen)
 {
-       *zb = (struct zbuf) {
+       *zb = (struct zbuf){
                .buf = buf,
                .end = (uint8_t *)buf + len,
                .head = buf,
@@ -58,7 +59,7 @@ void zbuf_reset(struct zbuf *zb)
 
 void zbuf_reset_head(struct zbuf *zb, void *ptr)
 {
-       zassert((void*)zb->buf <= ptr && ptr <= (void*)zb->tail);
+       zassert((void *)zb->buf <= ptr && ptr <= (void *)zb->tail);
        zb->head = ptr;
 }
 
@@ -84,9 +85,12 @@ ssize_t zbuf_read(struct zbuf *zb, int fd, size_t maxlen)
                maxlen = zbuf_tailroom(zb);
 
        r = read(fd, zb->tail, maxlen);
-       if (r > 0) zb->tail += r;
-       else if (r == 0) r = -2;
-       else if (r < 0 && ERRNO_IO_RETRY(errno)) r = 0;
+       if (r > 0)
+               zb->tail += r;
+       else if (r == 0)
+               r = -2;
+       else if (r < 0 && ERRNO_IO_RETRY(errno))
+               r = 0;
 
        return r;
 }
@@ -103,9 +107,10 @@ ssize_t zbuf_write(struct zbuf *zb, int fd)
                zb->head += r;
                if (zb->head == zb->tail)
                        zbuf_reset(zb);
-       }
-       else if (r == 0) r = -2;
-       else if (r < 0 && ERRNO_IO_RETRY(errno)) r = 0;
+       } else if (r == 0)
+               r = -2;
+       else if (r < 0 && ERRNO_IO_RETRY(errno))
+               r = 0;
 
        return r;
 }
@@ -119,9 +124,12 @@ ssize_t zbuf_recv(struct zbuf *zb, int fd)
 
        zbuf_remove_headroom(zb);
        r = recv(fd, zb->tail, zbuf_tailroom(zb), 0);
-       if (r > 0) zb->tail += r;
-       else if (r == 0) r = -2;
-       else if (r < 0 && ERRNO_IO_RETRY(errno)) r = 0;
+       if (r > 0)
+               zb->tail += r;
+       else if (r == 0)
+               r = -2;
+       else if (r < 0 && ERRNO_IO_RETRY(errno))
+               r = 0;
        return r;
 }
 
@@ -145,7 +153,8 @@ void *zbuf_may_pull_until(struct zbuf *zb, const char *sep, struct zbuf *msg)
        uint8_t *ptr;
 
        ptr = memmem(zb->head, zbuf_used(zb), sep, seplen);
-       if (!ptr) return NULL;
+       if (!ptr)
+               return NULL;
 
        len = ptr - zb->head + seplen;
        zbuf_init(msg, zbuf_pulln(zb, len), len, len);
@@ -154,7 +163,7 @@ void *zbuf_may_pull_until(struct zbuf *zb, const char *sep, struct zbuf *msg)
 
 void zbufq_init(struct zbuf_queue *zbq)
 {
-       *zbq = (struct zbuf_queue) {
+       *zbq = (struct zbuf_queue){
                .queue_head = LIST_INITIALIZER(zbq->queue_head),
        };
 }
@@ -163,7 +172,8 @@ void zbufq_reset(struct zbuf_queue *zbq)
 {
        struct zbuf *buf, *bufn;
 
-       list_for_each_entry_safe(buf, bufn, &zbq->queue_head, queue_list) {
+       list_for_each_entry_safe(buf, bufn, &zbq->queue_head, queue_list)
+       {
                list_del(&buf->queue_list);
                zbuf_free(buf);
        }
@@ -181,10 +191,10 @@ int zbufq_write(struct zbuf_queue *zbq, int fd)
        ssize_t r;
        size_t iovcnt = 0;
 
-       list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list) {
-               iov[iovcnt++] = (struct iovec) {
-                       .iov_base = zb->head,
-                       .iov_len = zbuf_used(zb),
+       list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list)
+       {
+               iov[iovcnt++] = (struct iovec){
+                       .iov_base = zb->head, .iov_len = zbuf_used(zb),
                };
                if (iovcnt >= ZEBRA_NUM_OF(iov))
                        break;
@@ -194,7 +204,8 @@ int zbufq_write(struct zbuf_queue *zbq, int fd)
        if (r < 0)
                return r;
 
-       list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list) {
+       list_for_each_entry_safe(zb, zbn, &zbq->queue_head, queue_list)
+       {
                if (r < (ssize_t)zbuf_used(zb)) {
                        zb->head += r;
                        return 1;
@@ -215,6 +226,7 @@ void zbuf_copy(struct zbuf *zdst, struct zbuf *zsrc, size_t len)
 
        dst = zbuf_pushn(zdst, len);
        src = zbuf_pulln(zsrc, len);
-       if (!dst || !src) return;
+       if (!dst || !src)
+               return;
        memcpy(dst, src, len);
 }