Esempio n. 1
0
RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO  *io, const char *filename, int mode, int flags) {
	if (!io) {
		return NULL;
	}
	RIOMMapFileObj *mmo = R_NEW0 (RIOMMapFileObj);
	if (!mmo) {
		return NULL;
	}
	mmo->nocache = !strncmp (filename, "nocache://", 10);
	if (mmo->nocache) {
		filename += 10;
	}
	mmo->filename = strdup (filename);
	mmo->mode = mode;
	mmo->flags = flags;
	mmo->io_backref = io;
	if (flags & R_IO_WRITE) {
		mmo->fd = r_sandbox_open (filename, O_CREAT|O_RDWR, mode);
	} else {
		mmo->fd = r_sandbox_open (filename, O_RDONLY, mode);
	}
	if (mmo->fd == -1) {
		free (mmo->filename);
		free (mmo);
		return NULL;
	}
	if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) {
		mmo->rawio = 1;
		if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) {
			r_io_def_mmap_free (mmo);
			mmo = NULL;
		}
	}
	return mmo;
}
Esempio n. 2
0
RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO  *io, const char *filename, int mode, int perm) {
	if (!io) {
		return NULL;
	}
	RIOMMapFileObj *mmo = R_NEW0 (RIOMMapFileObj);
	if (!mmo) {
		return NULL;
	}
	mmo->nocache = !strncmp (filename, "nocache://", 10);
	if (mmo->nocache) {
		filename += 10;
	}
	mmo->filename = strdup (filename);
	mmo->mode = mode;
	mmo->perm = perm;
	mmo->io_backref = io;
	const int posixFlags = (perm & R_PERM_W) ? (perm & R_PERM_CREAT)
			? (O_RDWR | O_CREAT) : O_RDWR : O_RDONLY;
	mmo->fd = r_sandbox_open (filename, posixFlags, mode);
	if (mmo->fd == -1) {
		free (mmo->filename);
		free (mmo);
		return NULL;
	}
	if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) {
		mmo->rawio = 1;
		if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) {
			r_io_def_mmap_free (mmo);
			mmo = NULL;
		}
	}
	return mmo;
}
Esempio n. 3
0
static int r_io_def_mmap_close(RIODesc *fd) {
	if (!fd || !fd->data)
		return -1;
	r_io_def_mmap_free ( (RIOMMapFileObj *) fd->data);
	fd->data = NULL;
	return 0;
}
Esempio n. 4
0
RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO  *io, const char *filename, int mode, int flags) {
	RIOMMapFileObj *mmo = NULL;
	if (!io)
		return NULL;

	mmo = R_NEW0 (RIOMMapFileObj);
	if (!mmo)
		return NULL;

	mmo->filename = strdup (filename);
	mmo->mode = mode;
	mmo->flags = flags;
	mmo->io_backref = io;
	if (flags & R_IO_WRITE)
		mmo->fd = r_sandbox_open (filename, O_CREAT|O_RDWR, mode);
	else mmo->fd = r_sandbox_open (filename, O_RDONLY, mode);

	if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) {
		mmo->rawio = 1;
		if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) {
			r_io_def_mmap_free (mmo);
			mmo = NULL;
		}
	}
	return mmo;
}
Esempio n. 5
0
RIOMMapFileObj *r_io_def_mmap_create_new_file(RIO  *io, const char *filename, int mode, int flags) {
	RIOMMapFileObj *mmo = NULL;
	if (!io)
		return NULL;

	mmo = R_NEW0 (RIOMMapFileObj);
	if (!mmo)
		return NULL;

	mmo->filename = strdup (filename);
	mmo->fd = r_num_rand (0xFFFF); // XXX: Use r_io_fd api
	mmo->mode = mode;
	mmo->flags = flags;
	mmo->io_backref = io;

	if (!r_io_def_mmap_refresh_def_mmap_buf (mmo)) {
		r_io_def_mmap_free (mmo);
		mmo = NULL;
	}
	return mmo;
}