[PATCH 02 of 14] chg: add connectat as a utility function
Yuya Nishihara
yuya at tcha.org
Mon Apr 11 08:39:16 EDT 2016
On Mon, 11 Apr 2016 00:57:19 +0100, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1460322456 -3600
> # Sun Apr 10 22:07:36 2016 +0100
> # Node ID 97fbb23cf84c03ce59325e9de94902f40c68c8c8
> # Parent cecc773636dcaeaf6d5130831f400a77fb065a96
> chg: add connectat as a utility function
>
> We are going to use connectat and some platforms (namely FreeBSD) has it own
> native implementation. The signature is the same with FreeBSD's so we can
> switch to its native implementation easily with C macro later.
I'd rather give different function name than shadowing standard function
on some platforms.
> --- a/contrib/chg/util.c
> +++ b/contrib/chg/util.c
> @@ -8,6 +8,7 @@
> */
>
> #include <errno.h>
> +#include <fcntl.h>
> #include <signal.h>
> #include <stdarg.h>
> #include <stdio.h>
> @@ -178,3 +179,18 @@
> return -WTERMSIG(status);
> return 127;
> }
> +
> +int connectat(int fd, int s, const struct sockaddr *addr, socklen_t addrlen)
> +{
> + if (fd == AT_FDCWD)
> + return connect(s, addr, addrlen);
> + int cwdfd = open(".", O_DIRECTORY);
> + if (cwdfd == -1)
> + abortmsgerrno("cannot open cwd");
^^^^^^^^^^^^^
> + fchdirx(fd);
^^^^^^^
Obviously this isn't compatible with the native implementation.
More information about the Mercurial-devel
mailing list