Skip to content

Commit c76de5a

Browse files
committed
Add script to generate list of errno value macros
1 parent 9918925 commit c76de5a

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

tools/build/generate-constants.pl

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env perl
2+
3+
use strict;
4+
use warnings;
5+
6+
use POSIX;
7+
8+
print <<"END_HEADER";
9+
# DO NOT EDIT THIS FILE.
10+
#
11+
# This file is generated automatically from
12+
# $0
13+
#
14+
# Any changes made here will be lost.
15+
#
16+
END_HEADER
17+
18+
my @errno_values;
19+
20+
my $max_errno_name_len = 0;
21+
foreach my $name (sort grep { /^E[A-Z]+$/ } keys %POSIX::) {
22+
my $code = POSIX->can($name);
23+
24+
next unless $code;
25+
26+
my $value = eval { $code->() };
27+
28+
next unless defined $value;
29+
30+
push @errno_values, [ $name, $value ];
31+
32+
if(length($name) > $max_errno_name_len) {
33+
$max_errno_name_len = length($name);
34+
}
35+
}
36+
37+
my $format = ".macro_const POSIX_%-${max_errno_name_len}s %d\n";
38+
39+
foreach my $pair (@errno_values) {
40+
my ( $name, $value ) = @$pair;
41+
42+
printf $format, $name, $value;
43+
}

0 commit comments

Comments
 (0)