| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/src/getlimits.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /* getlimits - print various platform dependent limits. | - | ||||||
| 2 | Copyright (C) 2008-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 | /* Written by Pádraig Brady */ | - | ||||||
| 18 | - | |||||||
| 19 | #include <config.h> /* sets _FILE_OFFSET_BITS=64 etc. */ | - | ||||||
| 20 | #include <stdio.h> | - | ||||||
| 21 | #include <sys/types.h> | - | ||||||
| 22 | #include <float.h> | - | ||||||
| 23 | - | |||||||
| 24 | #include "ftoastr.h" | - | ||||||
| 25 | #include "system.h" | - | ||||||
| 26 | #include "long-options.h" | - | ||||||
| 27 | - | |||||||
| 28 | #define PROGRAM_NAME "getlimits" | - | ||||||
| 29 | - | |||||||
| 30 | #define AUTHORS proper_name ("Padraig Brady") | - | ||||||
| 31 | - | |||||||
| 32 | #ifndef TIME_T_MAX | - | ||||||
| 33 | # define TIME_T_MAX TYPE_MAXIMUM (time_t) | - | ||||||
| 34 | #endif | - | ||||||
| 35 | - | |||||||
| 36 | #ifndef TIME_T_MIN | - | ||||||
| 37 | # define TIME_T_MIN TYPE_MINIMUM (time_t) | - | ||||||
| 38 | #endif | - | ||||||
| 39 | - | |||||||
| 40 | #ifndef SSIZE_MIN | - | ||||||
| 41 | # define SSIZE_MIN TYPE_MINIMUM (ssize_t) | - | ||||||
| 42 | #endif | - | ||||||
| 43 | - | |||||||
| 44 | #ifndef PID_T_MIN | - | ||||||
| 45 | # define PID_T_MIN TYPE_MINIMUM (pid_t) | - | ||||||
| 46 | #endif | - | ||||||
| 47 | - | |||||||
| 48 | /* These are not interesting to print. | - | ||||||
| 49 | * Instead of these defines it would be nice to be able to do | - | ||||||
| 50 | * #ifdef (TYPE##_MIN) in function macro below. */ | - | ||||||
| 51 | #define SIZE_MIN 0 | - | ||||||
| 52 | #define UCHAR_MIN 0 | - | ||||||
| 53 | #define UINT_MIN 0 | - | ||||||
| 54 | #define ULONG_MIN 0 | - | ||||||
| 55 | #define UINTMAX_MIN 0 | - | ||||||
| 56 | #define UID_T_MIN 0 | - | ||||||
| 57 | #define GID_T_MIN 0 | - | ||||||
| 58 | - | |||||||
| 59 | void | - | ||||||
| 60 | usage (int status) | - | ||||||
| 61 | { | - | ||||||
| 62 | if (status != EXIT_SUCCESS)
| 0 | ||||||
| 63 | emit_try_help (); never executed: end of block | 0 | ||||||
| 64 | else | - | ||||||
| 65 | { | - | ||||||
| 66 | printf (_("\ | - | ||||||
| 67 | Usage: %s\n\ | - | ||||||
| 68 | "), program_name); | - | ||||||
| 69 | - | |||||||
| 70 | fputs (_("\ | - | ||||||
| 71 | Output platform dependent limits in a format useful for shell scripts.\n\ | - | ||||||
| 72 | \n\ | - | ||||||
| 73 | "), stdout); | - | ||||||
| 74 | fputs (HELP_OPTION_DESCRIPTION, stdout); | - | ||||||
| 75 | fputs (VERSION_OPTION_DESCRIPTION, stdout); | - | ||||||
| 76 | emit_ancillary_info (PROGRAM_NAME); | - | ||||||
| 77 | } never executed: end of block | 0 | ||||||
| 78 | exit (status); never executed: exit (status); | 0 | ||||||
| 79 | } | - | ||||||
| 80 | - | |||||||
| 81 | /* Add one to the absolute value of the number whose textual | - | ||||||
| 82 | representation is BUF + 1. Do this in-place, in the buffer. | - | ||||||
| 83 | Return a pointer to the result, which is normally BUF + 1, but is | - | ||||||
| 84 | BUF if the representation grew in size. */ | - | ||||||
| 85 | static char const * | - | ||||||
| 86 | decimal_absval_add_one (char *buf) | - | ||||||
| 87 | { | - | ||||||
| 88 | bool negative = (buf[1] == '-'); | - | ||||||
| 89 | char *absnum = buf + 1 + negative; | - | ||||||
| 90 | char *p = absnum + strlen (absnum); | - | ||||||
| 91 | absnum[-1] = '0'; | - | ||||||
| 92 | while (*--p == '9')
| 0-729 | ||||||
| 93 | *p = '0'; never executed: *p = '0'; | 0 | ||||||
| 94 | ++*p; | - | ||||||
| 95 | char *result = MIN (absnum, p);
| 0-729 | ||||||
| 96 | if (negative)
| 270-459 | ||||||
| 97 | *--result = '-'; executed 270 times by 1 test: *--result = '-';Executed by:
| 270 | ||||||
| 98 | return result; executed 729 times by 1 test: return result;Executed by:
| 729 | ||||||
| 99 | } | - | ||||||
| 100 | - | |||||||
| 101 | #define PRINT_FLOATTYPE(N, T, FTOASTR, BUFSIZE) \ | - | ||||||
| 102 | static void \ | - | ||||||
| 103 | N (T x) \ | - | ||||||
| 104 | { \ | - | ||||||
| 105 | char buf[BUFSIZE]; \ | - | ||||||
| 106 | FTOASTR (buf, sizeof buf, FTOASTR_LEFT_JUSTIFY, 0, x); \ | - | ||||||
| 107 | puts (buf); \ | - | ||||||
| 108 | } | - | ||||||
| 109 | - | |||||||
| 110 | PRINT_FLOATTYPE (print_FLT, float, ftoastr, FLT_BUFSIZE_BOUND) executed 54 times by 1 test: end of blockExecuted by:
| 54 | ||||||
| 111 | PRINT_FLOATTYPE (print_DBL, double, dtoastr, DBL_BUFSIZE_BOUND) executed 54 times by 1 test: end of blockExecuted by:
| 54 | ||||||
| 112 | PRINT_FLOATTYPE (print_LDBL, long double, ldtoastr, LDBL_BUFSIZE_BOUND) executed 54 times by 1 test: end of blockExecuted by:
| 54 | ||||||
| 113 | - | |||||||
| 114 | int | - | ||||||
| 115 | main (int argc, char **argv) | - | ||||||
| 116 | { | - | ||||||
| 117 | char limit[1 + MAX (INT_BUFSIZE_BOUND (intmax_t), | - | ||||||
| 118 | INT_BUFSIZE_BOUND (uintmax_t))]; | - | ||||||
| 119 | - | |||||||
| 120 | initialize_main (&argc, &argv); | - | ||||||
| 121 | set_program_name (argv[0]); | - | ||||||
| 122 | setlocale (LC_ALL, ""); | - | ||||||
| 123 | bindtextdomain (PACKAGE, LOCALEDIR); | - | ||||||
| 124 | textdomain (PACKAGE); | - | ||||||
| 125 | - | |||||||
| 126 | initialize_exit_failure (EXIT_FAILURE); | - | ||||||
| 127 | atexit (close_stdout); | - | ||||||
| 128 | - | |||||||
| 129 | parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, | - | ||||||
| 130 | usage, AUTHORS, (char const *) NULL); | - | ||||||
| 131 | - | |||||||
| 132 | #define print_int(TYPE) \ | - | ||||||
| 133 | sprintf (limit + 1, "%"PRIuMAX, (uintmax_t) TYPE##_MAX); \ | - | ||||||
| 134 | printf (#TYPE"_MAX=%s\n", limit + 1); \ | - | ||||||
| 135 | printf (#TYPE"_OFLOW=%s\n", decimal_absval_add_one (limit)); \ | - | ||||||
| 136 | if (TYPE##_MIN) \ | - | ||||||
| 137 | { \ | - | ||||||
| 138 | sprintf (limit + 1, "%"PRIdMAX, (intmax_t) TYPE##_MIN); \ | - | ||||||
| 139 | printf (#TYPE"_MIN=%s\n", limit + 1); \ | - | ||||||
| 140 | printf (#TYPE"_UFLOW=%s\n", decimal_absval_add_one (limit)); \ | - | ||||||
| 141 | } | - | ||||||
| 142 | - | |||||||
| 143 | #define print_float(TYPE) \ | - | ||||||
| 144 | printf (#TYPE"_MIN="); print_##TYPE (TYPE##_MIN); \ | - | ||||||
| 145 | printf (#TYPE"_MAX="); print_##TYPE (TYPE##_MAX); | - | ||||||
| 146 | - | |||||||
| 147 | /* Variable sized ints */ | - | ||||||
| 148 | print_int (CHAR); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 149 | print_int (SCHAR); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 150 | print_int (UCHAR); dead code: { sprintf (limit + 1, "%" "l" "d" , (intmax_t) 0); printf ("UCHAR""_MIN=%s\n", limit + 1); printf ("UCHAR""_UFLOW=%s\n", decimal_absval_add_one (limit)); } | - | ||||||
| 151 | print_int (SHRT); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 152 | print_int (INT); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 153 | print_int (UINT); dead code: { sprintf (limit + 1, "%" "l" "d" , (intmax_t) 0); printf ("UINT""_MIN=%s\n", limit + 1); printf ("UINT""_UFLOW=%s\n", decimal_absval_add_one (limit)); } | - | ||||||
| 154 | print_int (LONG); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 155 | print_int (ULONG); dead code: { sprintf (limit + 1, "%" "l" "d" , (intmax_t) 0); printf ("ULONG""_MIN=%s\n", limit + 1); printf ("ULONG""_UFLOW=%s\n", decimal_absval_add_one (limit)); } | - | ||||||
| 156 | print_int (SIZE); dead code: { sprintf (limit + 1, "%" "l" "d" , (intmax_t) 0); printf ("SIZE""_MIN=%s\n", limit + 1); printf ("SIZE""_UFLOW=%s\n", decimal_absval_add_one (limit)); } | - | ||||||
| 157 | print_int (SSIZE); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 158 | print_int (TIME_T); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 159 | print_int (UID_T); dead code: { sprintf (limit + 1, "%" "l" "d" , (intmax_t) 0); printf ("UID_T""_MIN=%s\n", limit + 1); printf ("UID_T""_UFLOW=%s\n", decimal_absval_add_one (limit)); } | - | ||||||
| 160 | print_int (GID_T); dead code: { sprintf (limit + 1, "%" "l" "d" , (intmax_t) 0); printf ("GID_T""_MIN=%s\n", limit + 1); printf ("GID_T""_UFLOW=%s\n", decimal_absval_add_one (limit)); } | - | ||||||
| 161 | print_int (PID_T); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 162 | print_int (OFF_T); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 163 | print_int (INTMAX); executed 27 times by 1 test: end of blockExecuted by:
| 0-27 | ||||||
| 164 | print_int (UINTMAX); dead code: { sprintf (limit + 1, "%" "l" "d" , (intmax_t) 0); printf ("UINTMAX""_MIN=%s\n", limit + 1); printf ("UINTMAX""_UFLOW=%s\n", decimal_absval_add_one (limit)); } | - | ||||||
| 165 | - | |||||||
| 166 | /* Variable sized floats */ | - | ||||||
| 167 | print_float (FLT); | - | ||||||
| 168 | print_float (DBL); | - | ||||||
| 169 | print_float (LDBL); | - | ||||||
| 170 | - | |||||||
| 171 | return EXIT_SUCCESS; executed 27 times by 1 test: return 0 ;Executed by:
| 27 | ||||||
| 172 | } | - | ||||||
| Source code | Switch to Preprocessed file |