/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2021 Todd C. Miller <[email protected]>4*5* Permission to use, copy, modify, and distribute this software for any6* purpose with or without fee is hereby granted, provided that the above7* copyright notice and this permission notice appear in all copies.8*9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16*/1718#include <config.h>1920#include <stdio.h>21#include <string.h>22#include <time.h>23#include <errno.h>2425#include <sudo_compat.h>26#include <sudo_debug.h>27#include <sudo_iolog.h>2829/*30* I/O log wrapper for fflush/gzflush.31*/32bool33iolog_flush(struct iolog_file *iol, const char **errstr)34{35debug_decl(iolog_flush, SUDO_DEBUG_UTIL);36bool ret = true;3738#ifdef HAVE_ZLIB_H39if (iol->compressed) {40int errnum;41if (gzflush(iol->fd.g, Z_SYNC_FLUSH) != Z_OK) {42if (errstr != NULL) {43*errstr = gzerror(iol->fd.g, &errnum);44if (errnum == Z_ERRNO)45*errstr = strerror(errno);46}47ret = false;48}49} else50#endif51{52if (fflush(iol->fd.f) != 0) {53if (errstr != NULL)54*errstr = strerror(errno);55ret = false;56}57}5859debug_return_bool(ret);60}616263