mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-05 04:30:16 +02:00
b2/boom.c: move opening of file as stdin to separate function
This commit is contained in:
parent
1817efd6dc
commit
08b1ed1c51
28
b2/boom.c
28
b2/boom.c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user