OpenCoverage

yes.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/yes.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* yes - output a string repeatedly until killed-
2 Copyright (C) 1991-2018 Free Software Foundation, Inc.-
3-
4 This program is free software: you can redistribute it and/or modify-
5 it under the terms of the GNU General Public License as published by-
6 the Free Software Foundation, either version 3 of the License, or-
7 (at your option) any later version.-
8-
9 This program is distributed in the hope that it will be useful,-
10 but WITHOUT ANY WARRANTY; without even the implied warranty of-
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
12 GNU General Public License for more details.-
13-
14 You should have received a copy of the GNU General Public License-
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */-
16-
17/* David MacKenzie <djm@gnu.ai.mit.edu> */-
18-
19#include <config.h>-
20#include <stdio.h>-
21#include <sys/types.h>-
22#include <getopt.h>-
23-
24#include "system.h"-
25-
26#include "error.h"-
27#include "full-write.h"-
28#include "long-options.h"-
29-
30/* The official name of this program (e.g., no 'g' prefix). */-
31#define PROGRAM_NAME "yes"-
32-
33#define AUTHORS proper_name ("David MacKenzie")-
34-
35static struct option const long_options[] =-
36{-
37 {NULL, 0, NULL, 0}-
38};-
39-
40void-
41usage (int status)-
42{-
43 if (status != EXIT_SUCCESS)
status != 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 3 times by 1 test
Evaluated by:
  • yes
3
44 emit_try_help ();
executed 3 times by 1 test: end of block
Executed by:
  • yes
3
45 else-
46 {-
47 printf (_("\-
48Usage: %s [STRING]...\n\-
49 or: %s OPTION\n\-
50"),-
51 program_name, program_name);-
52-
53 fputs (_("\-
54Repeatedly output a line with all specified STRING(s), or 'y'.\n\-
55\n\-
56"), stdout);-
57 fputs (HELP_OPTION_DESCRIPTION, stdout);-
58 fputs (VERSION_OPTION_DESCRIPTION, stdout);-
59 emit_ancillary_info (PROGRAM_NAME);-
60 }
executed 3 times by 1 test: end of block
Executed by:
  • yes
3
61 exit (status);
executed 6 times by 1 test: exit (status);
Executed by:
  • yes
6
62}-
63-
64int-
65main (int argc, char **argv)-
66{-
67 initialize_main (&argc, &argv);-
68 set_program_name (argv[0]);-
69 setlocale (LC_ALL, "");-
70 bindtextdomain (PACKAGE, LOCALEDIR);-
71 textdomain (PACKAGE);-
72-
73 atexit (close_stdout);-
74-
75 parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,-
76 usage, AUTHORS, (char const *) NULL);-
77 if (getopt_long (argc, argv, "+", long_options, NULL) != -1)
getopt_long (a...d *)0) ) != -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 47 times by 1 test
Evaluated by:
  • yes
3-47
78 usage (EXIT_FAILURE);
executed 3 times by 1 test: usage ( 1 );
Executed by:
  • yes
3
79-
80 char **operands = argv + optind;-
81 char **operand_lim = argv + argc;-
82 if (optind == argc)
optind == argcDescription
TRUEevaluated 23 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 24 times by 1 test
Evaluated by:
  • yes
23-24
83 *operand_lim++ = bad_cast ("y");
executed 23 times by 1 test: *operand_lim++ = bad_cast ("y");
Executed by:
  • yes
23
84-
85 /* Buffer data locally once, rather than having the-
86 large overhead of stdio buffering each item. */-
87 size_t bufalloc = 0;-
88 bool reuse_operand_strings = true;-
89 for (char **operandp = operands; operandp < operand_lim; operandp++)
operandp < operand_limDescription
TRUEevaluated 4145 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 47 times by 1 test
Evaluated by:
  • yes
47-4145
90 {-
91 size_t operand_len = strlen (*operandp);-
92 bufalloc += operand_len + 1;-
93 if (operandp + 1 < operand_lim
operandp + 1 < operand_limDescription
TRUEevaluated 4098 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 47 times by 1 test
Evaluated by:
  • yes
47-4098
94 && *operandp + operand_len + 1 != operandp[1])
*operandp + op...!= operandp[1]Description
TRUEnever evaluated
FALSEevaluated 4098 times by 1 test
Evaluated by:
  • yes
0-4098
95 reuse_operand_strings = false;
never executed: reuse_operand_strings = 0 ;
0
96 }
executed 4145 times by 1 test: end of block
Executed by:
  • yes
4145
97-
98 /* Improve performance by using a buffer size greater than BUFSIZ / 2. */-
99 if (bufalloc <= BUFSIZ / 2)
bufalloc <= 8192 / 2Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 7 times by 1 test
Evaluated by:
  • yes
7-40
100 {-
101 bufalloc = BUFSIZ;-
102 reuse_operand_strings = false;-
103 }
executed 40 times by 1 test: end of block
Executed by:
  • yes
40
104-
105 /* Fill the buffer with one copy of the output. If possible, reuse-
106 the operands strings; this wins when the buffer would be large. */-
107 char *buf = reuse_operand_strings ? *operands : xmalloc (bufalloc);
reuse_operand_stringsDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 40 times by 1 test
Evaluated by:
  • yes
7-40
108 size_t bufused = 0;-
109 for (char **operandp = operands; operandp < operand_lim; operandp++)
operandp < operand_limDescription
TRUEevaluated 4145 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 47 times by 1 test
Evaluated by:
  • yes
47-4145
110 {-
111 size_t operand_len = strlen (*operandp);-
112 if (! reuse_operand_strings)
! reuse_operand_stringsDescription
TRUEevaluated 139 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 4006 times by 1 test
Evaluated by:
  • yes
139-4006
113 memcpy (buf + bufused, *operandp, operand_len);
executed 139 times by 1 test: memcpy (buf + bufused, *operandp, operand_len);
Executed by:
  • yes
139
114 bufused += operand_len;-
115 buf[bufused++] = ' ';-
116 }
executed 4145 times by 1 test: end of block
Executed by:
  • yes
4145
117 buf[bufused - 1] = '\n';-
118-
119 /* If a larger buffer was allocated, fill it by repeating the buffer-
120 contents. */-
121 size_t copysize = bufused;-
122 for (size_t copies = bufalloc / copysize; --copies; )
--copiesDescription
TRUEevaluated 109414 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 47 times by 1 test
Evaluated by:
  • yes
47-109414
123 {-
124 memcpy (buf + bufused, buf, copysize);-
125 bufused += copysize;-
126 }
executed 109414 times by 1 test: end of block
Executed by:
  • yes
109414
127-
128 /* Repeatedly output the buffer until there is a write error; then fail. */-
129 while (full_write (STDOUT_FILENO, buf, bufused) == bufused)
full_write ( 1...ed) == bufusedDescription
TRUEevaluated 8995 times by 1 test
Evaluated by:
  • yes
FALSEevaluated 45 times by 1 test
Evaluated by:
  • yes
45-8995
130 continue;
executed 8995 times by 1 test: continue;
Executed by:
  • yes
8995
131 error (0, errno, _("standard output"));-
132 return EXIT_FAILURE;
executed 45 times by 1 test: return 1 ;
Executed by:
  • yes
45
133}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2