Skip to content

Instantly share code, notes, and snippets.

@elieux
Created February 4, 2017 17:12
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/7b25ae87b981ddac537b09841e6ec079 to your computer and use it in GitHub Desktop.
Save elieux/7b25ae87b981ddac537b09841e6ec079 to your computer and use it in GitHub Desktop.
Cygwin unlinked /proc/self/fd/* is ENOENT
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <alloca.h>
int main() {
char path[] = "tmp";
int r;
int fd = open(path, O_WRONLY|O_CREAT|O_EXCL|O_TRUNC, 0600);
printf("open(\"%s\", ...) = %d\n", path, fd);
r = unlink(path);
printf("unlink(\"%s\") = %d\n", path, r);
char *buf = alloca(20);
sprintf(buf, "/proc/self/fd/%d", fd);
r = open(buf, O_RDONLY);
printf("open(\"%s\", ...) = %d\n", buf, r);
return 0;
}
Linux$ gcc -Wall test.c -o x && ./test
open("tmp", ...) = 3
unlink("tmp") = 0
open("/proc/self/fd/3", ...) = 4
Cygwin$ gcc -Wall test.c -o x && ./test
open("tmp", ...) = 3
unlink("tmp") = 0
open("/proc/self/fd/3", ...) = -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment