1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-06-29 00:03:52 +03:00

b2/boom.c: move opening of file as stdin to separate function

This commit is contained in:
Werner Almesberger 2012-04-28 11:41:07 -03:00
parent 1817efd6dc
commit 08b1ed1c51

View File

@ -18,6 +18,22 @@
#include "lang.h"
static void open_stdin(const char *name)
{
int fd;
fd = open(name, O_RDONLY);
if (fd < 0) {
perror(name);
exit(1);
}
if (dup2(fd, 0) < 0) {
perror("dup2");
exit(1);
}
}
static void usage(const char *name)
{
fprintf(stderr, "usage: %s [file]\n", name);
@ -27,21 +43,11 @@ static void usage(const char *name)
int main(int argc, char **argv)
{
int fd;
switch (argc) {
case 1:
break;
case 2:
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror(argv[1]);
exit(1);
}
if (dup2(fd, 0) < 0) {
perror("dup2");
exit(1);
}
open_stdin(argv[1]);
break;
default:
usage(*argv);