]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/buffer.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / buffer.c
index 7929b3709dc1d7cfc239533f42e5997d81efcfdd..63df56a6d23d6dba715bc600ecc7dda006c4e738 100644 (file)
@@ -1,22 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Buffering of output and input.
  * Copyright (C) 1998 Kunihiro Ishiguro
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra 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, or (at your
- * option) any later version.
- *
- * GNU Zebra 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; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -59,7 +44,7 @@ struct buffer_data {
 /* It should always be true that: 0 <= sp <= cp <= size */
 
 /* Default buffer size (used if none specified).  It is rounded up to the
-   next page boundery. */
+   next page boundary. */
 #define BUFFER_SIZE_DEFAULT            4096
 
 #define BUFFER_DATA_FREE(D) XFREE(MTYPE_BUFFER_DATA, (D))
@@ -357,7 +342,8 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
 
                        iov_size =
                                ((iov_index > IOV_MAX) ? IOV_MAX : iov_index);
-                       if ((nbytes = writev(fd, c_iov, iov_size)) < 0) {
+                       nbytes = writev(fd, c_iov, iov_size);
+                       if (nbytes < 0) {
                                flog_err(EC_LIB_SOCKET,
                                         "%s: writev to fd %d failed: %s",
                                         __func__, fd, safe_strerror(errno));
@@ -370,7 +356,8 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width,
                }
        }
 #else  /* IOV_MAX */
-       if ((nbytes = writev(fd, iov, iov_index)) < 0)
+       nbytes = writev(fd, iov, iov_index);
+       if (nbytes < 0)
                flog_err(EC_LIB_SOCKET, "%s: writev to fd %d failed: %s",
                         __func__, fd, safe_strerror(errno));
 #endif /* IOV_MAX */
@@ -472,13 +459,17 @@ buffer_status_t buffer_write(struct buffer *b, int fd, const void *p,
                /* Buffer is not empty, so do not attempt to write the new data.
                 */
                nbytes = 0;
-       else if ((nbytes = write(fd, p, size)) < 0) {
-               if (ERRNO_IO_RETRY(errno))
-                       nbytes = 0;
-               else {
-                       flog_err(EC_LIB_SOCKET, "%s: write error on fd %d: %s",
-                                __func__, fd, safe_strerror(errno));
-                       return BUFFER_ERROR;
+       else {
+               nbytes = write(fd, p, size);
+               if (nbytes < 0) {
+                       if (ERRNO_IO_RETRY(errno))
+                               nbytes = 0;
+                       else {
+                               flog_err(EC_LIB_SOCKET,
+                                        "%s: write error on fd %d: %s",
+                                        __func__, fd, safe_strerror(errno));
+                               return BUFFER_ERROR;
+                       }
                }
        }
        /* Add any remaining data to the buffer. */