Skip to content

Instantly share code, notes, and snippets.

@elieux
Created November 19, 2019 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elieux/2436a3f04cda3dedf94e3b7781299b39 to your computer and use it in GitHub Desktop.
Save elieux/2436a3f04cda3dedf94e3b7781299b39 to your computer and use it in GitHub Desktop.
Cygwin vs Linux fifo bug?
/*
* $ gcc -Wall -Wextra -std=c11 fifo.c -o fifo
*
* Linux:
* $ ./fifo
* $ echo $?
* 0
*
* Cygwin:
* $ ./fifo
* fread: Communication error on send
* $ echo $?
* 1
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
int main(void) {
const char path[] = "/tmp/fifo";
const char sent[] = "msg";
const size_t len = strlen(sent);
char *const read = (char *)malloc(len);
int r;
size_t s;
r = mkfifo(path, 0666);
if (r != 0) {
perror("mkfifo");
return 1;
}
FILE* f = fopen(path, "w+");
if (f == NULL) {
perror("fopen");
return 1;
}
s = fwrite(sent, 1, len, f);
if (s != len) {
perror("fwrite");
return 1;
}
s = fread(read, 1, len, f);
if (s != len) {
perror("fread");
return 1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment