3 // Copyright (C) 2004 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.
29 #define ENSC_WRAPPERS_PREFIX "chain-echo: "
30 #define ENSC_WRAPPERS_FCNTL 1
31 #define ENSC_WRAPPERS_UNISTD 1
32 #define ENSC_WRAPPERS_IO 1
35 int wrapper_exit_code = 255;
38 showHelp(char const *cmd)
40 WRITE_MSG(1, "Usage: ");
43 " [--] <file> <data> <command> <args>*\n\n"
44 "Please report bugs to " PACKAGE_BUGREPORT "\n");
52 "chain-echo " VERSION " -- puts data into a file within a command-chain\n"
53 "This program is part of " PACKAGE_STRING "\n\n"
54 "Copyright (C) 2004 Enrico Scholz\n"
55 VERSION_COPYRIGHT_DISCLAIMER);
59 int main(int argc, char *argv[])
65 if (strcmp(argv[1], "--help") ==0) showHelp(argv[0]);
66 if (strcmp(argv[1], "--version")==0) showVersion();
67 if (strcmp(argv[1], "--") ==0) ++idx;
71 WRITE_MSG(2, "Not enough parameters; use '--help' for more information\n");
72 return wrapper_exit_code;
75 if (argv[idx][0]=='\0')
78 fd = Eopen(argv[idx], O_WRONLY|O_NOFOLLOW, 0600);
79 Efcntl(fd, F_SETFD, FD_CLOEXEC);
82 if (argv[idx+1][0]!='\0')
83 EwriteAll(fd, argv[idx+1], strlen(argv[idx+1]));
85 Eexecv(argv[idx+2], argv+idx+2);