cleanups
[util-vserver.git] / util-vserver / src / chroot-cat.c
1 // $Id$    --*- c -*--
2
3 // Copyright (C) 2003 Enrico Scholz <>
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; version 2 of the License.
8 //  
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.
13 //  
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.
17
18
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "util.h"
24 #include "wrappers.h"
25
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <stdio.h>
29
30 int     wrapper_exit_code = 1;
31
32 int main(int argc, char *argv[])
33 {
34   int           fd;
35
36   if (argc!=2) {
37     WRITE_MSG(2, "Usage: chroot-cat file\n");
38     return EXIT_FAILURE;
39   }
40
41   Echroot(".");
42   Echdir("/");
43
44   fd = Eopen(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0644);
45   for (;;) {
46     char                buf[4096];
47     char const *        ptr=buf;
48     ssize_t             len;
49
50     len = Eread(0, buf, sizeof(buf));
51     if (len<=0) break;
52
53     while (len>0) {
54       size_t    l = Ewrite(fd, ptr, len);
55       ptr += l;
56       len -= l;
57     }
58   }
59   Eclose(fd);
60
61   return EXIT_SUCCESS;
62 }