ck_errf.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /usr/bin/env perl
  2. # Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the OpenSSL license (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # This is just a quick script to scan for cases where the 'error'
  9. # function name in a XXXerr() macro is wrong.
  10. #
  11. # Run in the top level by going
  12. # perl util/ck_errf.pl */*.c */*/*.c
  13. #
  14. use strict;
  15. use warnings;
  16. my $err_strict = 0;
  17. my $bad = 0;
  18. foreach my $file (@ARGV) {
  19. if ( $file eq "-strict" ) {
  20. $err_strict = 1;
  21. next;
  22. }
  23. open( IN, "<$file" ) || die "Can't open $file, $!";
  24. my $func = "";
  25. while (<IN>) {
  26. if ( !/;$/ && /^\**([a-zA-Z_].*[\s*])?([A-Za-z_0-9]+)\(.*([),]|$)/ ) {
  27. /^([^()]*(\([^()]*\)[^()]*)*)\(/;
  28. $1 =~ /([A-Za-z_0-9]*)$/;
  29. $func = $1;
  30. $func =~ tr/A-Z/a-z/;
  31. }
  32. if ( /([A-Z0-9]+)err\(([^,]+)/ && !/ckerr_ignore/ ) {
  33. my $errlib = $1;
  34. my $n = $2;
  35. if ( $func eq "" ) {
  36. print "$file:$.:???:$n\n";
  37. $bad = 1;
  38. next;
  39. }
  40. if ( $n !~ /([^_]+)_F_(.+)$/ ) {
  41. #print "check -$file:$.:$func:$n\n";
  42. next;
  43. }
  44. my $lib = $1;
  45. $n = $2;
  46. if ( $lib ne $errlib ) {
  47. print "$file:$.:$func:$n [${errlib}err]\n";
  48. $bad = 1;
  49. next;
  50. }
  51. $n =~ tr/A-Z/a-z/;
  52. if ( $n ne $func && $errlib ne "SYS" ) {
  53. print "$file:$.:$func:$n\n";
  54. $bad = 1;
  55. next;
  56. }
  57. # print "$func:$1\n";
  58. }
  59. }
  60. close(IN);
  61. }
  62. if ( $bad && $err_strict ) {
  63. print STDERR "FATAL: error discrepancy\n";
  64. exit 1;
  65. }