LCOV - code coverage report
Current view: top level - lib/libc/minimal/source/stdout - stdout_console.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 30 10.0 %
Date: 2022-08-18 11:36:24 Functions: 1 4 25.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 24 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* stdout_console.c */
       2                 :            : 
       3                 :            : /*
       4                 :            :  * Copyright (c) 2014 Wind River Systems, Inc.
       5                 :            :  *
       6                 :            :  * SPDX-License-Identifier: Apache-2.0
       7                 :            :  */
       8                 :            : 
       9                 :            : #include <stdio.h>
      10                 :            : #include <sys/libc-hooks.h>
      11                 :            : #include <syscall_handler.h>
      12                 :            : #include <string.h>
      13                 :            : 
      14                 :          0 : static int _stdout_hook_default(int c)
      15                 :            : {
      16                 :            :         (void)(c);  /* Prevent warning about unused argument */
      17                 :            : 
      18                 :          0 :         return EOF;
      19                 :            : }
      20                 :            : 
      21                 :            : static int (*_stdout_hook)(int) = _stdout_hook_default;
      22                 :            : 
      23                 :          1 : void __stdout_hook_install(int (*hook)(int))
      24                 :            : {
      25                 :          1 :         _stdout_hook = hook;
      26                 :          1 : }
      27                 :            : 
      28                 :          0 : int z_impl_zephyr_fputc(int c, FILE *stream)
      29                 :            : {
      30   [ #  #  #  # ]:          0 :         return (stream == stdout || stream == stderr) ? _stdout_hook(c) : EOF;
      31                 :            : }
      32                 :            : 
      33                 :            : #ifdef CONFIG_USERSPACE
      34                 :            : static inline int z_vrfy_zephyr_fputc(int c, FILE *stream)
      35                 :            : {
      36                 :            :         return z_impl_zephyr_fputc(c, stream);
      37                 :            : }
      38                 :            : #include <syscalls/zephyr_fputc_mrsh.c>
      39                 :            : #endif
      40                 :            : 
      41                 :            : int fputc(int c, FILE *stream)
      42                 :            : {
      43                 :          0 :         return zephyr_fputc(c, stream);
      44                 :            : }
      45                 :            : 
      46                 :            : int fputs(const char *ZRESTRICT s, FILE *ZRESTRICT stream)
      47                 :            : {
      48                 :          0 :         int len = strlen(s);
      49                 :            :         int ret;
      50                 :            : 
      51                 :          0 :         ret = fwrite(s, 1, len, stream);
      52                 :            : 
      53         [ #  # ]:          0 :         return len == ret ? 0 : EOF;
      54                 :            : }
      55                 :            : 
      56                 :          0 : size_t z_impl_zephyr_fwrite(const void *ZRESTRICT ptr, size_t size,
      57                 :            :                             size_t nitems, FILE *ZRESTRICT stream)
      58                 :            : {
      59                 :            :         size_t i;
      60                 :            :         size_t j;
      61                 :            :         const unsigned char *p;
      62                 :            : 
      63   [ #  #  #  #  :          0 :         if ((stream != stdout && stream != stderr) ||
                   #  # ]
      64         [ #  # ]:          0 :             (nitems == 0) || (size == 0)) {
      65                 :          0 :                 return 0;
      66                 :            :         }
      67                 :            : 
      68                 :          0 :         p = ptr;
      69                 :          0 :         i = nitems;
      70                 :            :         do {
      71                 :          0 :                 j = size;
      72                 :            :                 do {
      73         [ #  # ]:          0 :                         if (_stdout_hook((int) *p++) == EOF) {
      74                 :          0 :                                 goto done;
      75                 :            :                         }
      76                 :          0 :                         j--;
      77         [ #  # ]:          0 :                 } while (j > 0);
      78                 :            : 
      79                 :          0 :                 i--;
      80         [ #  # ]:          0 :         } while (i > 0);
      81                 :            : 
      82                 :          0 : done:
      83                 :          0 :         return (nitems - i);
      84                 :            : }
      85                 :            : 
      86                 :            : #ifdef CONFIG_USERSPACE
      87                 :            : static inline size_t z_vrfy_zephyr_fwrite(const void *ZRESTRICT ptr,
      88                 :            :                                           size_t size, size_t nitems,
      89                 :            :                                           FILE *ZRESTRICT stream)
      90                 :            : {
      91                 :            : 
      92                 :            :         Z_OOPS(Z_SYSCALL_MEMORY_ARRAY_READ(ptr, nitems, size));
      93                 :            :         return z_impl_zephyr_fwrite((const void *ZRESTRICT)ptr, size,
      94                 :            :                                     nitems, (FILE *ZRESTRICT)stream);
      95                 :            : }
      96                 :            : #include <syscalls/zephyr_fwrite_mrsh.c>
      97                 :            : #endif
      98                 :            : 
      99                 :            : size_t fwrite(const void *ZRESTRICT ptr, size_t size, size_t nitems,
     100                 :            :                           FILE *ZRESTRICT stream)
     101                 :            : {
     102                 :          0 :         return zephyr_fwrite(ptr, size, nitems, stream);
     103                 :            : }
     104                 :            : 
     105                 :            : 
     106                 :            : int puts(const char *s)
     107                 :            : {
     108         [ #  # ]:          0 :         if (fputs(s, stdout) == EOF) {
     109                 :          0 :                 return EOF;
     110                 :            :         }
     111                 :            : 
     112         [ #  # ]:          0 :         return fputc('\n', stdout) == EOF ? EOF : 0;
     113                 :            : }

Generated by: LCOV version 1.14