windows closefrom

This commit is contained in:
Jean-Francois Dockes
2022-01-19 12:30:40 +01:00
parent 497b61e017
commit fbcf0f42e9
2 changed files with 58 additions and 56 deletions
+44
View File
@@ -0,0 +1,44 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include "closefrom.h"
int main(int argc, char **argv)
{
int i;
int fd0 = open("/etc/group", 0);
if (fd0 < 0) {
perror("open /etc/group");
exit(1);
}
if (dup2(fd0, 11) < 0) {
perror("dup2->11");
exit(1);
}
if (dup2(fd0, 19) < 0) {
perror("dup2->19");
exit(1);
}
if (dup2(fd0, 99)< 0) {
perror("dup2->99 (ok)");
}
if (dup2(fd0, 999) < 0) {
perror("dup3->999 (ok)");
}
libclf_closefrom(11);
for (i = 0; i < 10000; i++) {
if (fcntl(i, F_GETFL) != -1) {
fprintf(stderr, "Descriptor %d is still open", i);
if (i < 11)
fprintf(stderr, " (OK)\n");
else
fprintf(stderr, " (BAD)\n");
}
}
exit(0);
}