Skip to content

ioctl(pipe_fd, FIONREAD, &n) fails on pipe file descriptors #26711

@Ryan2026R

Description

@Ryan2026R

Version of emscripten/emsdk:

5.0.6

ioctl(pipe_read, FIONREAD, &avail) should return 0 and set avail to the byte count buffered in the pipe. Under Emscripten it returns 28 and leaves avail = 0 even when the pipe has data ready to read.

Failing command line in full:

$ emcc -O0 -Wall fionread.c -o a.out.js
$ node a.out.js
FIONREAD: ret=28 avail=0

The same program on native Linux prints FIONREAD: ret=0 avail=5.

Example code snippet:

#include <unistd.h>
#include <sys/ioctl.h>
#include <stdio.h>

int main(void) {
    int pfd[2];
    pipe(pfd);
    write(pfd[1], "hello", 5);

    int avail = 0;
    int r = ioctl(pfd[0], FIONREAD, &avail);
    printf("FIONREAD: ret=%d avail=%d\n", r, avail);

    close(pfd[0]); close(pfd[1]);
    return (r == 0 && avail == 5) ? 0 : 1;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions