1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-07-03 00:32:00 +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" #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) static void usage(const char *name)
{ {
fprintf(stderr, "usage: %s [file]\n", 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 main(int argc, char **argv)
{ {
int fd;
switch (argc) { switch (argc) {
case 1: case 1:
break; break;
case 2: case 2:
fd = open(argv[1], O_RDONLY); open_stdin(argv[1]);
if (fd < 0) {
perror(argv[1]);
exit(1);
}
if (dup2(fd, 0) < 0) {
perror("dup2");
exit(1);
}
break; break;
default: default:
usage(*argv); usage(*argv);