LCOV - code coverage report
Current view: top level - src/posix - system_posix.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 12 12 100.0 %
Date: 2026-11-26 02:32:31 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 2 4 50.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright 2007-2025 David Robillard <d@drobilla.net>
       2                 :            : // SPDX-License-Identifier: ISC
       3                 :            : 
       4                 :            : #include "../system.h"
       5                 :            : #include "../zix_config.h"
       6                 :            : 
       7                 :            : #include <fcntl.h>
       8                 :            : #include <stddef.h>
       9                 :            : #include <stdint.h>
      10                 :            : #include <sys/stat.h>
      11                 :            : #include <sys/types.h>
      12                 :            : #include <unistd.h>
      13                 :            : 
      14                 :            : #ifndef MAX
      15                 :            : #  define MAX(a, b) (((a) > (b)) ? (a) : (b))
      16                 :            : #endif
      17                 :            : 
      18                 :            : #ifdef PAGE_SIZE
      19                 :            : #  define ZIX_DEFAULT_PAGE_SIZE PAGE_SIZE
      20                 :            : #else
      21                 :            : #  define ZIX_DEFAULT_PAGE_SIZE 4096U
      22                 :            : #endif
      23                 :            : 
      24                 :            : uint32_t
      25                 :         24 : zix_system_page_size(void)
      26                 :            : {
      27                 :            : #if USE_SYSCONF
      28                 :         24 :   const long r = sysconf(_SC_PAGE_SIZE);
      29         [ +  - ]:         24 :   return r > 0L ? (uint32_t)r : ZIX_DEFAULT_PAGE_SIZE;
      30                 :            : #else
      31                 :            :   return (uint32_t)ZIX_DEFAULT_PAGE_SIZE;
      32                 :            : #endif
      33                 :            : }
      34                 :            : 
      35                 :            : uint32_t
      36                 :         24 : zix_system_max_block_size(const struct stat* const s1,
      37                 :            :                           const struct stat* const s2,
      38                 :            :                           const uint32_t           fallback)
      39                 :            : {
      40                 :         24 :   const blksize_t size = MAX(s1->st_blksize, s2->st_blksize);
      41                 :            : 
      42         [ +  - ]:         24 :   return (size > 0) ? (uint32_t)size : fallback;
      43                 :            : }
      44                 :            : 
      45                 :            : int
      46                 :         91 : zix_system_open(const char* const path, const int flags, const mode_t mode)
      47                 :            : {
      48                 :            : #ifdef O_CLOEXEC
      49                 :         91 :   return open(path, flags | O_CLOEXEC, mode); // NOLINT(*-signed-bitwise)
      50                 :            : #else
      51                 :            :   return open(path, flags, mode);
      52                 :            : #endif
      53                 :            : }
      54                 :            : 
      55                 :            : int
      56                 :         82 : zix_system_close(const int fd)
      57                 :            : {
      58                 :         82 :   return close(fd);
      59                 :            : }
      60                 :            : 
      61                 :            : ssize_t
      62                 :         60 : zix_system_read(const int fd, void* const buf, const size_t count)
      63                 :            : {
      64                 :         60 :   return read(fd, buf, count);
      65                 :            : }

Generated by: LCOV version 1.16