Пример #1
0
Файл: io.c Проект: m403/radare2
static inline RList *__getioplugin_many(RIO *io, const char *_uri, int flags, int mode) {
	RIOPlugin *plugin, *iop = NULL;
	RList *list_fds = NULL;
	RListIter *iter;
	RIODesc *desc;
	char *uri = strdup (_uri);
	for (;;) {
		// resolve
		plugin = r_io_plugin_resolve (io, uri, 1);
		if (plugin && plugin->open_many) {
			// open
			list_fds = plugin->open_many (io, uri, flags, mode);
			if (io->redirect) {
				free (uri);
				uri = strdup (io->redirect);
				r_io_redirect (io, NULL);
				continue;
			}
		}
		break;
	}

	if (!list_fds) {
		free (uri);
		return NULL;
	}

	r_list_foreach (list_fds, iter, desc) {
		desc->uri = strdup (uri);
	}
Пример #2
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;
}
Пример #3
0
/* opens many files, without mapping them. This should be discussed */
R_API RList* r_io_open_many(RIO* io, const char* uri, int flags, int mode) {
	RList* desc_list;
	RListIter* iter;
	RIODesc* desc;
	if (!io || !io->files || !uri) {
		return NULL;
	}
	RIOPlugin* plugin = r_io_plugin_resolve (io, uri, 1);
	if (!plugin || !plugin->open_many || !plugin->close) {
		return NULL;
	}
	if (!(desc_list = plugin->open_many (io, uri, flags, mode))) {
		return NULL;
	}
	r_list_foreach (desc_list, iter, desc) {
		if (desc) {
			if (!desc->plugin) {
				desc->plugin = plugin;
			}
			if (!desc->uri) {
				desc->uri = strdup (uri);
			}
			//should autofd be honored here?
			r_io_desc_add (io, desc);
			if (!io->desc) {
				io->desc = desc;
			}
		}
	}
	return desc_list;
}
Пример #4
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;
}
Пример #5
0
Файл: io.c Проект: m403/radare2
static inline RIODesc *__getioplugin(RIO *io, const char *_uri, int flags, int mode) {
	RIOPlugin *plugin;
	RIODesc *desc = NULL;
	char *uri = strdup (_uri? _uri: "");
	char *redir = NULL;
	for (;;) {
		plugin = r_io_plugin_resolve (io, uri, 0);
		if (plugin && plugin->open) {
			desc = plugin->open (io, uri, flags, mode);
			if (io->redirect) {
				redir = uri;
				uri = strdup (io->redirect);
				r_io_redirect (io, NULL);
				continue;
			}
			if (desc) {
				desc->uri = uri;
				desc->referer = redir;
				io->plugin = plugin;
			}
		}
		break;
	}
	if (!desc) {
		plugin = r_io_plugin_get_default (io, uri, 0);
		desc = (plugin && plugin->open)
			? plugin->open (io, uri, flags, mode)
			: NULL;
		if (desc) {
			desc->uri = uri;
			io->plugin = plugin;
		}
	}
	if (!desc) {
		free (uri);
		io->plugin = NULL;
	}
	return desc;
}