9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 8e1140bdf618ee898e69f637d6fd8ebf8152931c
parent fc7ec07fdb7c1ba4ee2e53ab8fb777d59dadfbf9
Author: Roberto E. Vargas Caballero <roberto@clue.aero>
Date:   Tue, 13 Aug 2019 09:25:52 +0200

[namespace] Simplify namespace()

Using assignation expressions allow to simplify
the code a lot, and removing the error tag
makes the code more straight forward.

Change-Id: I5b542046439a91889f4afc7a9bb799dd678bcc74

Diffstat:
Mtarget/hosted/rom.c | 72++++++++++++++++++++++--------------------------------------------------
Mtarget/native/rom.c | 9+++------
2 files changed, 25 insertions(+), 56 deletions(-)

diff --git a/target/hosted/rom.c b/target/hosted/rom.c @@ -55,60 +55,32 @@ namespace(void) static char setout[] = "addout /dev/uart0/raw\n"; /* Standard input set to 0 */ - kin = open("#c/raw", O_READ); - if (kin != 0) { - kerror("open:#c/raw read"); - goto error; - } + if ((kin = open("#c/raw", O_READ)) < 0) + panic("open:#c/raw read"); /* Standard output set to 1 */ - kout = open("#c/raw", O_WRITE); - if (kout != 1) { - kerror("open:#c/raw write"); - goto error; - } + if ((kout = open("#c/raw", O_WRITE)) < 0) + panic("open:#c/raw write"); /* Standard error set to 2 */ - kerr = open("#c/raw", O_WRITE); - if (kerr != 2) { - kerror("open:#c/raw write"); - goto error; - } - - if (bind("#t0", "/dev/uart0") < 0) { - kerror("bind:/dev/uart0"); - goto error; - } - if (bind("#c", "/dev/cons") < 0) { - kerror("bind:/dev/cons"); - goto error; - } - if (bind("#b", "/dev/blk") < 0) { - kerror("bind:/dev/blk"); - goto error; - } - - if ((fd = open("/dev/cons/ctl", O_WRITE)) < 0) { - kerror("open:/dev/cons/ctl write"); - goto error; - } - if (write(fd, setin, sizeof(setin)) < 0) { - kerror("write:setin"); - goto error; - } - if (write(fd, setout, sizeof(setout)) < 0) { - kerror("write:setout"); - goto error; - } - if (close(fd) < 0) { - kerror("close:/dev/cons/ctl"); - goto error; - } - - return; - -error: - panic("namespace"); + if ((kerr = open("#c/raw", O_WRITE)) < 0) + panic("open:#c/raw write"); + + if (bind("#t0", "/dev/uart0") < 0) + panic("bind:/dev/uart0"); + if (bind("#c", "/dev/cons") < 0) + panic("bind:/dev/cons"); + if (bind("#b", "/dev/blk") < 0) + panic("bind:/dev/blk"); + + if ((fd = open("/dev/cons/ctl", O_WRITE)) < 0) + panic("open:/dev/cons/ctl write"); + if (write(fd, setin, sizeof(setin)) < 0) + panic("write:setin"); + if (write(fd, setout, sizeof(setout)) < 0) + panic("write:setout"); + if (close(fd) < 0) + panic("close:/dev/cons/ctl"); } int diff --git a/target/native/rom.c b/target/native/rom.c @@ -99,18 +99,15 @@ namespace(void) static char setout[] = "addout /dev/uart0/raw\n"; /* Standard input set to 0 */ - kin = open("#c/raw", O_READ); - if (kin != 0) + if ((kin = open("#c/raw", O_READ)) < 0) panic("open:#c/raw read"); /* Standard output set to 1 */ - kout = open("#c/raw", O_WRITE); - if (kout != 1) + if ((kout = open("#c/raw", O_WRITE)) < 0) panic("open:#c/raw write"); /* Standard error set to 2 */ - kerr = open("#c/raw", O_WRITE); - if (kerr != 2) { + if ((kerr = open("#c/raw", O_WRITE)) < 0) panic("open:#c/raw write"); if (bind("#c", "/dev/cons") < 0) {