Print system limits from limits.h

This program prints the contents of limits.h

#!/home/ben/software/install/bin/perl
use warnings;
use strict;
my $include = 'limits.h';

my %defines;
get_defines ($include, \%defines);
print_defines (\%defines);

exit;

sub get_defines
{
    my ($include, $defines) = @_;
    my $file = "/usr/include/$include";
    open my $in, "<", $file or die $!;
    while (<$in>) {
        if (/^#\s*include\s*<(.*)>/) {
            my $subinclude = $1;
            get_defines ($subinclude, $defines);
            next;
        }
        if (/^#\s*define\s+(\w*)\s+(.*)/) {
            my $macro = $1;
            my $value = $2;
            $value =~ s!\s+|/\*.*?\*/|\(|\)!!g;
            while ($defines->{$value}) {
                $value = $defines->{$value};
            }
            $defines->{$macro} = $value;
            next;
        }
    }
    close $in or die $!;
}

sub print_defines
{
    my ($defines) = @_;
    for my $k (sort keys %$defines) {
        if ($k !~ /^_/ && $k !~ /^[a-z]+$/) {
            print "$k = $defines->{$k}\n";
        }
    }
}

(download)

The output of the example looks like this:

ARG_MAX = 262144
BC_BASE_MAX = 99
BC_DIM_MAX = 2048
BC_SCALE_MAX = 99
BC_STRING_MAX = 1000
CHAR_BIT = 8
CHAR_MAX = 0x7f
CHAR_MIN = -0x7f-1
CHILD_MAX = 40
COLL_WEIGHTS_MAX = 0
EXPR_NEST_MAX = 32
GID_MAX = 0xffffffffU
INT_MAX = 0x7fffffff
INT_MIN = -0x7fffffff-1
IOV_MAX = 1024
LINE_MAX = 2048
LINK_MAX = 32767
LLONG_MAX = 0x7fffffffffffffffLL
LLONG_MIN = -0x7fffffffffffffffLL-1
LONG_BIT = 32
LONG_MAX = 0x7fffffffL
LONG_MIN = -0x7fffffffL-1
MAX_CANON = 255
MAX_INPUT = 255
MB_LEN_MAX = 6
MQ_PRIO_MAX = 64
NAME_MAX = 255
NGROUPS_MAX = 1023
NL_ARGMAX = 99
NL_LANGMAX = 31
NL_MSGMAX = 32767
NL_NMAX = 1
NL_SETMAX = 255
NL_TEXTMAX = 2048
OFF_MAX = 0x7fffffffffffffffLL
OFF_MIN = -0x7fffffffffffffffLL-1
OPEN_MAX = 64
PASS_MAX = 128
PATH_MAX = 1024
PIPE_BUF = 512
QUAD_MAX = 0x7fffffffffffffffLL
QUAD_MIN = -0x7fffffffffffffffLL-1
RE_DUP_MAX = 255
SCHAR_MAX = 0x7f
SCHAR_MIN = -0x7f-1
SHRT_MAX = 0x7fff
SHRT_MIN = -0x7fff-1
SIZE_T_MAX = 0xffffffffU
SSIZE_MAX = 0x7fffffff
UCHAR_MAX = 0xff
UID_MAX = 0xffffffffU
UINT_MAX = 0xffffffffU
ULLONG_MAX = 0xffffffffffffffffULL
ULONG_MAX = 0xffffffffUL
UQUAD_MAX = 0xffffffffffffffffULL
USHRT_MAX = 0xffff
WORD_BIT = 32

Web links


Copyright © Ben Bullock 2009-2017. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com). / Privacy / Disclaimer