altmbr: an alternative MBR which ignores the active flag
[profile/ivi/syslinux.git] / mbr / checksize.pl
1 ## -----------------------------------------------------------------------
2 ##
3 ##   Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
4 ##
5 ##   This program is free software; you can redistribute it and/or modify
6 ##   it under the terms of the GNU General Public License as published by
7 ##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ##   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ##   (at your option) any later version; incorporated herein by reference.
10 ##
11 ## -----------------------------------------------------------------------
12
13 ##
14 ## checksize.pl
15 ##
16 ## Check the size of a binary file and pad it with zeroes to that size
17 ##
18
19 use bytes;
20
21 ($file, $maxsize, $padsize) = @ARGV;
22
23 $padsize = $maxsize unless(defined($padsize));
24
25 open(FILE, '+<', $file) or die;
26 @st = stat(FILE);
27 if (!defined($size = $st[7])) {
28     die "$0: $file: $!\n";
29 }
30 if ($size > $maxsize) {
31     print STDERR "$file: too big ($size > $maxsize)\n";
32     exit 1;
33 } elsif ($size < $padsize) {
34     seek(FILE, $size, 0);
35     print FILE "\0" x ($padsize-$size);
36 }
37
38 exit 0;