unix/minit

opendevconsole.c in master
Repositories | Summary | Log | Files | README | COPYING

opendevconsole.c (337B) download


 1#include <fcntl.h>
 2#include <unistd.h>
 3#include <write12.h>
 4#include <stdlib.h>
 5
 6void opendevconsole() {
 7  int fd;
 8  if ((fd=open("/dev/console",O_RDWR|O_NOCTTY))>=0) {
 9    if (dup2(fd,0) != 0 ||
10	dup2(fd,1) != 1 ||
11	dup2(fd,2) != 2) {
12      __write2("dup2 failed unexpectedly.\n");
13      exit(111);
14    }
15    if (fd>2) close(fd);
16  }
17}