static int unix_open(URLContext *h, const char *filename, int flags)
{
    UnixContext *s = h->priv_data;
    int fd, ret;
    av_strstart(filename, "unix:", &filename);
    s->addr.sun_family = AF_UNIX;
    av_strlcpy(s->addr.sun_path, filename, sizeof(s->addr.sun_path));
    if ((fd = ff_socket(AF_UNIX, s->type, 0)) < 0)
        return ff_neterrno();
    if (s->listen) {
        fd = ff_listen_bind(fd, (struct sockaddr *)&s->addr,
                            sizeof(s->addr), s->timeout, h);
        if (fd < 0) {
            ret = fd;
            goto fail;
        }
    } else {
        ret = ff_listen_connect(fd, (struct sockaddr *)&s->addr,
                                sizeof(s->addr), s->timeout, h);
        if (ret < 0)
            goto fail;
    }
    s->fd = fd;
    return 0;
fail:
    if (s->listen && ret != EADDRINUSE)
        unlink(s->addr.sun_path);
    if (fd >= 0)
        closesocket(fd);
    return ret;
}
['static int unix_open(URLContext *h, const char *filename, int flags)\n{\n    UnixContext *s = h->priv_data;\n    int fd, ret;\n    av_strstart(filename, "unix:", &filename);\n    s->addr.sun_family = AF_UNIX;\n    av_strlcpy(s->addr.sun_path, filename, sizeof(s->addr.sun_path));\n    if ((fd = ff_socket(AF_UNIX, s->type, 0)) < 0)\n        return ff_neterrno();\n    if (s->listen) {\n        fd = ff_listen_bind(fd, (struct sockaddr *)&s->addr,\n                            sizeof(s->addr), s->timeout, h);\n        if (fd < 0) {\n            ret = fd;\n            goto fail;\n        }\n    } else {\n        ret = ff_listen_connect(fd, (struct sockaddr *)&s->addr,\n                                sizeof(s->addr), s->timeout, h);\n        if (ret < 0)\n            goto fail;\n    }\n    s->fd = fd;\n    return 0;\nfail:\n    if (s->listen && ret != EADDRINUSE)\n        unlink(s->addr.sun_path);\n    if (fd >= 0)\n        closesocket(fd);\n    return ret;\n}', 'size_t av_strlcpy(char *dst, const char *src, size_t size)\n{\n    size_t len = 0;\n    while (++len < size && *src)\n        *dst++ = *src++;\n    if (len <= size)\n        *dst = 0;\n    return len + strlen(src) - 1;\n}', 'static inline int ff_socket(int domain, int type, int protocol)\n{\n    return socket(domain, type | SOCK_CLOEXEC, protocol);\n}', 'int ff_listen_bind(int fd, const struct sockaddr *addr,\n                   socklen_t addrlen, int timeout, URLContext *h)\n{\n    int ret;\n    int reuse = 1;\n    struct pollfd lp = { fd, POLLIN, 0 };\n    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));\n    ret = bind(fd, addr, addrlen);\n    if (ret)\n        return ff_neterrno();\n    ret = listen(fd, 1);\n    if (ret)\n        return ff_neterrno();\n    ret = ff_poll_interrupt(&lp, 1, timeout, &h->interrupt_callback);\n    if (ret < 0)\n        return ret;\n    ret = accept(fd, NULL, NULL);\n    if (ret < 0)\n        return ff_neterrno();\n    closesocket(fd);\n    ff_socket_nonblock(ret, 1);\n    return ret;\n}', 'static int ff_poll_interrupt(struct pollfd *p, nfds_t nfds, int timeout,\n                             AVIOInterruptCB *cb)\n{\n    int runs = timeout / POLLING_TIME;\n    int ret = 0;\n    do {\n        if (ff_check_interrupt(cb))\n            return AVERROR_EXIT;\n        ret = poll(p, nfds, POLLING_TIME);\n        if (ret != 0)\n            break;\n    } while (timeout < 0 || runs-- > 0);\n    if (!ret)\n        return AVERROR(ETIMEDOUT);\n    if (ret < 0)\n        return AVERROR(errno);\n    return ret;\n}', 'int ff_check_interrupt(AVIOInterruptCB *cb)\n{\n    int ret;\n    if (cb && cb->callback && (ret = cb->callback(cb->opaque)))\n        return ret;\n    return 0;\n}']