3 // Copyright (C) 2005 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
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; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #define ENSC_WRAPPERS_PREFIX "check-unixfile: "
32 #define ENSC_WRAPPERS_FCNTL 1
33 #define ENSC_WRAPPERS_UNISTD 1
36 int wrapper_exit_code = 255;
39 showHelp(int fd, char const *cmd)
41 WRITE_MSG(fd, "Usage: ");
45 "Please report bugs to " PACKAGE_BUGREPORT "\n");
53 "check-unixfile " VERSION " -- execute some basic fileformat checks\n"
54 "This program is part of " PACKAGE_STRING "\n\n"
55 "Copyright (C) 2005 Enrico Scholz\n"
56 VERSION_COPYRIGHT_DISCLAIMER);
61 checkFile(char const *fname)
63 int fd = Eopen(fname, O_RDONLY, 0);
64 off_t l = Elseek(fd, 0, SEEK_END);
65 char const * data = 0;
68 if (l>100*1024*1024) {
69 WRITE_MSG(2, "WARNING: '");
71 WRITE_STR(2, "' is too large for a vserver configuration file\n");
75 data = mmap(0, l, PROT_READ, MAP_PRIVATE, fd, 0);
76 if (data==MAP_FAILED) {
78 exit(wrapper_exit_code);
81 if (data[l-1]!='\n') {
82 WRITE_MSG(2, "WARNING: '");
84 WRITE_MSG(2, "' does not end on newline\n");
88 munmap(const_cast(char *)(data), l);
96 int main(int argc, char *argv[])
103 if (strcmp(argv[1], "--help") ==0) showHelp(1, argv[0]);
104 if (strcmp(argv[1], "--version")==0) showVersion();
105 if (strcmp(argv[1], "--") ==0) ++idx;
108 for (; idx<argc; ++idx)
109 if (checkFile(argv[idx])) passed = true;
113 else if (passed) return 2;