1 /* getlimits - print various platform dependent limits.
2 Copyright (C) 2008-2011 Free Software Foundation, Inc.
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.
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.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Pádraig Brady */
19 #include <config.h> /* sets _FILE_OFFSET_BITS=64 etc. */
21 #include <sys/types.h>
25 #include "long-options.h"
27 #define PROGRAM_NAME "getlimits"
29 #define AUTHORS proper_name_utf8 ("Padraig Brady", "P\303\241draig Brady")
32 # define TIME_T_MAX TYPE_MAXIMUM (time_t)
36 # define TIME_T_MIN TYPE_MINIMUM (time_t)
40 # define SSIZE_MIN TYPE_MINIMUM (ssize_t)
44 # define PID_T_MIN TYPE_MINIMUM (pid_t)
47 /* These are not interesting to print.
48 * Instead of these defines it would be nice to be able to do
49 * #ifdef (TYPE##_MIN) in function macro below. */
61 if (status
!= EXIT_SUCCESS
)
62 fprintf (stderr
, _("Try `%s --help' for more information.\n"),
71 Output platform dependent limits in a format useful for shell scripts.\n\
74 fputs (HELP_OPTION_DESCRIPTION
, stdout
);
75 fputs (VERSION_OPTION_DESCRIPTION
, stdout
);
76 emit_ancillary_info ();
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. */
86 decimal_absval_add_one (char *buf
)
88 bool negative
= (buf
[1] == '-');
89 char *absnum
= buf
+ 1 + negative
;
90 char *p
= absnum
+ strlen (absnum
);
95 char *result
= MIN (absnum
, p
);
102 main (int argc
, char **argv
)
104 char limit
[1 + MAX (INT_BUFSIZE_BOUND (intmax_t),
105 INT_BUFSIZE_BOUND (uintmax_t))];
107 initialize_main (&argc
, &argv
);
108 set_program_name (argv
[0]);
109 setlocale (LC_ALL
, "");
110 bindtextdomain (PACKAGE
, LOCALEDIR
);
111 textdomain (PACKAGE
);
113 initialize_exit_failure (EXIT_FAILURE
);
114 atexit (close_stdout
);
116 parse_long_options (argc
, argv
, PROGRAM_NAME
, PACKAGE_NAME
, VERSION
,
117 usage
, AUTHORS
, (char const *) NULL
);
119 #define print_int(TYPE) \
120 sprintf (limit + 1, "%"PRIuMAX, (uintmax_t) TYPE##_MAX); \
121 printf (#TYPE"_MAX=%s\n", limit + 1); \
122 printf (#TYPE"_OFLOW=%s\n", decimal_absval_add_one (limit)); \
125 sprintf (limit + 1, "%"PRIdMAX, (intmax_t) TYPE##_MIN); \
126 printf (#TYPE"_MIN=%s\n", limit + 1); \
127 printf (#TYPE"_UFLOW=%s\n", decimal_absval_add_one (limit)); \
130 #define print_float(TYPE) \
131 printf (#TYPE"_MIN=%Le\n", (long double)TYPE##_MIN); \
132 printf (#TYPE"_MAX=%Le\n", (long double)TYPE##_MAX);
134 /* Variable sized ints */
153 /* Variable sized floats */