libc: handle positive fd on "always-failing" creates (brk and dup)

This commit is contained in:
Giacomo Tesio 2017-01-16 23:53:05 +01:00
parent 042e206d13
commit e2b5953d99
2 changed files with 17 additions and 1 deletions

View File

@ -30,6 +30,11 @@ dup(int oldfd, int newfd)
f = create("#d/new", -1, in.aslong);
if(f == -1)
return -1;
if(f >= 0){
/* this should never happen */
close(f);
return -1;
}
out.aslong = ~f;
return out.fd[1];
}

View File

@ -18,7 +18,18 @@ enum
Round = 7
};
#define brk_(p) ((uintptr_t)~create("#0/brk/set", -1, p))
uintptr_t
brk_(uintptr_t p)
{
long f;
f = create("#0/brk/set", -1, p);
if(f >= 0){
/* this should never happen */
close(f);
return -1;
}
return (uintptr_t)~f;
}
int
brk(void *p)