static int _hostfs_dup(oe_fd_t* desc, oe_fd_t** new_file_out)
{
    int ret = -1;
    file_t* file = _cast_file(desc);
    file_t* new_file = NULL;

    if (!new_file_out)
        OE_RAISE_ERRNO(OE_EINVAL);

    *new_file_out = NULL;

    /* Check parameters. */
    if (!file)
        OE_RAISE_ERRNO(OE_EINVAL);

    /* Create and initialize the new file structure. */
    {
        if (!(new_file = oe_calloc(1, sizeof(file_t))))
            OE_RAISE_ERRNO(oe_errno);

        new_file->base.type = OE_FD_TYPE_FILE;
        new_file->base.ops.file = _get_file_ops();
        new_file->magic = FILE_MAGIC;
    }

    /* Call the host to perform the dup(). */
    {
        oe_host_fd_t retval = -1;

        if (oe_syscall_dup_ocall(&retval, file->host_fd) != OE_OK)
            OE_RAISE_ERRNO(OE_EINVAL);

        if (retval == -1)
            OE_RAISE_ERRNO(oe_errno);

        new_file->host_fd = retval;
    }

    *new_file_out = &new_file->base;
    new_file = NULL;
    ret = 0;

done:

    if (new_file)
        oe_free(new_file);

    return ret;
}
static int _hostfs_dup(oe_fd_t* desc, oe_fd_t** new_file_out)
{
    int ret = -1;
    file_t* file = _cast_file(desc);
    file_t* new_file = NULL;

    if (!new_file_out)
        OE_RAISE_ERRNO(OE_EINVAL);

    *new_file_out = NULL;

     
    if (!file)
        OE_RAISE_ERRNO(OE_EINVAL);

     
    {
        if (!(new_file = oe_calloc(1, sizeof(file_t))))
            OE_RAISE_ERRNO(oe_errno);

        new_file->base.type = OE_FD_TYPE_FILE;
        new_file->base.ops.file = _get_file_ops();
        new_file->magic = FILE_MAGIC;
    }

     
    {
        oe_host_fd_t retval = -1;

        if (oe_syscall_dup_ocall(&retval, file->host_fd) != OE_OK)
            OE_RAISE_ERRNO(OE_EINVAL);

        if (retval == -1)
            OE_RAISE_ERRNO(oe_errno);

        new_file->host_fd = retval;
    }

    *new_file_out = &new_file->base;
    new_file = NULL;
    ret = 0;

done:

    if (new_file)
        oe_free(new_file);

    return ret;
}