Implement swrap_dup too.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21592 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -1837,40 +1837,11 @@ _PUBLIC_ int swrap_close(int fd)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
_PUBLIC_ int swrap_dup(int oldd)
|
static int
|
||||||
|
dup_internal(const struct socket_info *si_oldd, int fd)
|
||||||
{
|
{
|
||||||
struct socket_info *si;
|
struct socket_info *si_newd;
|
||||||
|
|
||||||
si = find_socket_info(oldd);
|
|
||||||
if (si == NULL)
|
|
||||||
return real_dup(oldd);
|
|
||||||
|
|
||||||
abort(); /* write code here */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
_PUBLIC_ int swrap_dup2(int oldd, int newd)
|
|
||||||
{
|
|
||||||
struct socket_info *si_newd, *si_oldd;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
if (newd == oldd)
|
|
||||||
return newd;
|
|
||||||
|
|
||||||
si_oldd = find_socket_info(oldd);
|
|
||||||
si_newd = find_socket_info(newd);
|
|
||||||
|
|
||||||
if (si_oldd == NULL && si_newd == NULL)
|
|
||||||
return real_dup2(oldd, newd);
|
|
||||||
|
|
||||||
fd = real_dup2(si_oldd->fd, newd);
|
|
||||||
if (fd < 0)
|
|
||||||
return fd;
|
|
||||||
|
|
||||||
/* close new socket first */
|
|
||||||
if (si_newd)
|
|
||||||
swrap_close(newd);
|
|
||||||
|
|
||||||
si_newd = (struct socket_info *)calloc(1, sizeof(struct socket_info));
|
si_newd = (struct socket_info *)calloc(1, sizeof(struct socket_info));
|
||||||
|
|
||||||
si_newd->fd = fd;
|
si_newd->fd = fd;
|
||||||
@@ -1897,3 +1868,46 @@ _PUBLIC_ int swrap_dup2(int oldd, int newd)
|
|||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_PUBLIC_ int swrap_dup(int oldd)
|
||||||
|
{
|
||||||
|
struct socket_info *si;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
si = find_socket_info(oldd);
|
||||||
|
if (si == NULL)
|
||||||
|
return real_dup(oldd);
|
||||||
|
|
||||||
|
fd = real_dup(si->fd);
|
||||||
|
if (fd < 0)
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
return dup_internal(si, fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_PUBLIC_ int swrap_dup2(int oldd, int newd)
|
||||||
|
{
|
||||||
|
struct socket_info *si_newd, *si_oldd;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
if (newd == oldd)
|
||||||
|
return newd;
|
||||||
|
|
||||||
|
si_oldd = find_socket_info(oldd);
|
||||||
|
si_newd = find_socket_info(newd);
|
||||||
|
|
||||||
|
if (si_oldd == NULL && si_newd == NULL)
|
||||||
|
return real_dup2(oldd, newd);
|
||||||
|
|
||||||
|
fd = real_dup2(si_oldd->fd, newd);
|
||||||
|
if (fd < 0)
|
||||||
|
return fd;
|
||||||
|
|
||||||
|
/* close new socket first */
|
||||||
|
if (si_newd)
|
||||||
|
swrap_close(newd);
|
||||||
|
|
||||||
|
return dup_internal(si_oldd, fd);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user