Beispiel #1
0
static inline RIODesc *__getioplugin(RIO *io, const char *uri, int flags, int mode) {
	RIOPlugin *plugin, *iop = NULL;
	RIODesc *desc = NULL;
	for (;;) {
		plugin = r_io_plugin_resolve (io, uri);
		if (plugin && plugin->open) {
			desc = plugin->open (io, uri, flags, mode);
			if (io->redirect) {
				uri = io->redirect;
				r_io_redirect (io, NULL);
				continue;
			}
			if (desc != NULL) {
				r_io_desc_add (io, desc);
				if (desc->fd != -1)
					r_io_plugin_open (io, desc->fd, plugin);
				if (desc != io->fd)
					iop = plugin;
			}
		}
		break;
	}
	io->plugin = iop;
	return desc;
}
Beispiel #2
0
R_API RIODesc *r_io_open(struct r_io_t *io, const char *file, int flags, int mode) {
	RIODesc *desc = NULL;
	int fd = -2;
	char *uri = strdup (file);
	struct r_io_plugin_t *plugin;
	if (!io) return NULL;
	for (;;) {
		plugin = r_io_plugin_resolve (io, uri);
		if (plugin && plugin->open) {
			desc = plugin->open (io, uri, flags, mode);
			if (io->redirect) {
				free ((void *)uri);
				uri = strdup (io->redirect);
				r_io_redirect (io, NULL);
				continue;
			}
			if (desc != NULL) {
				r_io_desc_add (io, desc);
				fd = desc->fd;
				if (fd != -1)
					r_io_plugin_open (io, fd, plugin);
				if (desc != io->fd)
					io->plugin = plugin;
			}
		}
		break;
	}
	if (fd == -2) {
#if __WINDOWS__
		if (flags & R_IO_WRITE) {
			fd = open (file, O_BINARY | 1);
			if (fd == -1)
				creat (file, O_BINARY);
			fd = open (file, O_BINARY | 1);
		} else fd = open (file, O_BINARY);
#else
		fd = open (file, (flags&R_IO_WRITE)?O_RDWR:O_RDONLY, mode);
#endif
	}
	if (fd >= 0) {
		if (desc == NULL)
			desc = r_io_desc_new (io->plugin, fd, file, flags, mode, NULL);
		r_io_desc_add (io, desc);
		r_io_set_fd (io, desc);
	}
	free ((void *)uri);
	return desc;
}