Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.0 KiB

  1. #---------------------------------------------------------------------
  2. package UnicodeCheck;
  3. #
  4. # Copyright (c) Microsoft Corporation. All rights reserved.
  5. #
  6. # Version: 1.00 (05/15/2001) : (MikeR) Helper functions for Unicode checks
  7. #---------------------------------------------------------------------
  8. use strict;
  9. use vars qw(@ISA @EXPORT $VERSION);
  10. use Carp;
  11. use Exporter;
  12. use lib $ENV{ "RazzleToolPath" };
  13. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  14. use Logmsg;
  15. @ISA = qw(Exporter);
  16. @EXPORT = qw(IsFileUnicode);
  17. $VERSION = '1.00';
  18. sub IsFileUnicode( $ )
  19. {
  20. my $ThisFile = shift;
  21. my $ReturnCode = 0;
  22. if ( open( THISFILE, $ThisFile ) )
  23. {
  24. my $FirstLine;
  25. $FirstLine = <THISFILE>;
  26. if ((ord(substr($FirstLine,0,1))==255) && (ord(substr($FirstLine,1,1))==254))
  27. {
  28. logmsg( "Unicode signature is valid for file '$ThisFile'." );
  29. $ReturnCode = 1;
  30. }
  31. else
  32. {
  33. errmsg( "Unicode signature is invalid for '$ThisFile'!" );
  34. $ReturnCode = 0;
  35. }
  36. # Close the file...
  37. close( THISFILE );
  38. }
  39. else
  40. {
  41. # Cannot find file...
  42. errmsg( "Cannot open file to verify Unicode signature - '$ThisFile'!" );
  43. $ReturnCode = 0;
  44. }
  45. return $ReturnCode;
  46. }
  47. 1;
  48. __END__
  49. =head1 NAME
  50. UnicodeCheck - Helper functions to check Unicode cycles
  51. =head1 SYNOPSIS
  52. Call IsFileUnicode() with a full path to a file to determine if it's Unicode or not.
  53. Details and errors are logged using errmsg and logmsg. Return code is 1 if the file
  54. is Unicode (that is, it has the FFFE Unicode header), 0 otherwise.
  55. =head1 DESCRIPTION
  56. Used to help detect if files are Unicode or not.
  57. =head1 AUTHOR
  58. MikeR
  59. =head1 COPYRIGHT
  60. Copyright (c) Microsoft Corporation. All rights reserved.
  61. =cut