/* This is in fact very similar to the above: The open routines always need to watch out for a prepared wrapper handle to use replaced normal I/O. Two cases to consider: */
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
/* This is in fact very similar to the above: The open routines always need to watch out for a prepared wrapper handle to use replaced normal I/O. Two cases to consider: */
int attribute_align_arg mpg123_open_fd(mpg123_handle *mh, int fd)
{
	struct wrap_data* ioh;
	if(mh == NULL) return MPG123_ERR;
	mpg123_close(mh);
	ioh = mh->wrapperdata;
	if(ioh != NULL && ioh->iotype == IO_FD)
	{
		int err;
		err = MPG123_LARGENAME(mpg123_replace_reader_handle)(mh, wrap_read, wrap_lseek, wrap_io_cleanup);
		if(err != MPG123_OK) return MPG123_ERR;
		ioh->fd = fd;
		err = open_stream_handle(mh, ioh);
		if(err != MPG123_OK)
		{
			wrap_io_cleanup(ioh);
			return MPG123_ERR;
		}
		return MPG123_OK;
	}
	else return MPG123_LARGENAME(mpg123_open_fd)(mh, fd);
}