3 // Copyright (C) 2003,2004,2005 Enrico Scholz <>
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.
30 #define ENSC_WRAPPERS_UNISTD 1
31 #define ENSC_WRAPPERS_FCNTL 1
34 int wrapper_exit_code = 1;
37 showHelp(char const UNUSED *cmd)
40 "Usage: chroot-cat [-a] [--] <file>\n"
42 "Does something similarly to 'chroot . cat > <file>' without\n"
43 "the need for a 'cat' in the chroot.\n"
46 " -a ... append instead of truncate (do '>> <file>'\n"
47 " instead of '> <file>)\n\n"
48 "Please report bugs to " PACKAGE_BUGREPORT "\n");
56 "chroot-cat " VERSION " -- cat stdin into a chrooted file\n"
57 "This program is part of " PACKAGE_STRING "\n\n"
58 "Copyright (C) 2003,2004,2005 Enrico Scholz\n"
59 VERSION_COPYRIGHT_DISCLAIMER);
64 int main(int argc, char *argv[])
68 bool do_append = false;
71 if (strcmp(argv[idx], "--help") ==0) showHelp(argv[0]);
72 if (strcmp(argv[idx], "--version")==0) showVersion();
73 if (strcmp(argv[idx], "-a") ==0) { do_append = true; ++idx; }
74 if (strcmp(argv[idx], "--") ==0) ++idx;
78 WRITE_MSG(2, "Not enough parameters; use '--help' for more information\n");
79 return wrapper_exit_code;
85 fd = EopenD(argv[idx], O_WRONLY|O_CREAT| (do_append ? O_APPEND : O_TRUNC), 0644);
91 len = Eread(0, buf, sizeof(buf));
95 size_t l = Ewrite(fd, ptr, len);