Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ const wrap = (f) => (...args) => {
};

const translateFileAttributes = (fd, stats) => {
if (isTTY(fd)) {
return {
filetype: WASI_FILETYPE_CHARACTER_DEVICE,
rightsBase: RIGHTS_TTY_BASE,
rightsInheriting: RIGHTS_TTY_INHERITING,
};
}

switch (true) {
case stats.isBlockDevice():
return {
Expand All @@ -452,16 +460,8 @@ const translateFileAttributes = (fd, stats) => {
rightsInheriting: RIGHTS_BLOCK_DEVICE_INHERITING,
};
case stats.isCharacterDevice(): {
const filetype = WASI_FILETYPE_CHARACTER_DEVICE;
if (fd !== undefined && isTTY(fd)) {
return {
filetype,
rightsBase: RIGHTS_TTY_BASE,
rightsInheriting: RIGHTS_TTY_INHERITING,
};
}
return {
filetype,
filetype: WASI_FILETYPE_CHARACTER_DEVICE,
rightsBase: RIGHTS_CHARACTER_DEVICE_BASE,
rightsInheriting: RIGHTS_CHARACTER_DEVICE_INHERITING,
};
Expand Down Expand Up @@ -510,8 +510,9 @@ const stat = (wasi, fd) => {
if (!entry) {
throw WASI_EBADF;
}

if (entry.filetype === undefined) {
const stats = fs.fstatSync(entry.real);
const stats = isTTY(fd) ? void 0 : fs.fstatSync(entry.real);
const {
filetype, rightsBase, rightsInheriting,
} = translateFileAttributes(fd, stats);
Expand Down