Пример #1
0
static PyObject *
Wmii_write(Wmii *self, PyObject *args)
{
    const char *file;
    const char *data;

    IxpCFid *fid;

    if (!PyArg_ParseTuple(args, "ss", &file,  &data)) {
        PyErr_SetString(PyExc_TypeError, "Wmii.write() takes exactly 2 arguments");
        return NULL;
    }

    fid = ixp_open(self->client, file, P9_OWRITE);
    if(fid == NULL)
    {
        PyErr_SetObject(PyExc_IOError, PyString_FromFormat("Can't open file '%s'\n", file));
        return NULL;
    }

    ixp_write(fid, data, strlen(data));

    ixp_close(fid);

    Py_RETURN_NONE;
}
Пример #2
0
static PyObject *
Wmii_create(Wmii *self, PyObject *args)
{
    IxpCFid *fid;
    const char *file;
    const char *data;

    if (!PyArg_ParseTuple(args, "s|s", &file, &data)) {
        PyErr_SetString(PyExc_TypeError, "Wmii.create() requires 1 argument");
        return NULL;
    }

    fid = ixp_create(self->client, file, 0777, P9_OWRITE);
    if(fid == NULL)
    {
        PyErr_SetObject(PyExc_IOError, PyString_FromFormat("Can't create file '%s'\n", file));
    }

    if((fid->qid.type&P9_DMDIR) == 0)
    {
        if(strlen(data)) {
            ixp_write(fid, data, strlen(data));
        }
    }
    ixp_close(fid);
    Py_RETURN_NONE;
}
Пример #3
0
static int
xawrite(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file, *buf;
	int nbuf, i;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	file = EARGF(usage());
	fid = ixp_open(client, file, P9_OWRITE);
	if(fid == nil)
		fatal("Can't open file '%s': %r\n", file);

	nbuf = 1;
	for(i=0; i < argc; i++)
		nbuf += strlen(argv[i]) + (i > 0);
	buf = emalloc(nbuf);
	buf[0] = '\0';
	while(argc) {
		strcat(buf, ARGF());
		if(argc)
			strcat(buf, " ");
	}

	if(ixp_write(fid, buf, nbuf) == -1)
		fatal("cannot write file '%s': %r\n", file);
	ixp_close(fid);
	free(buf);
	return 0;
}
Пример #4
0
/* Utility Functions */
static void
write_data(IxpCFid *fid, char *name) {
	void *buf;
	long len;

	buf = emalloc(fid->iounit);;
	do {
		len = read(0, buf, fid->iounit);
		if(len >= 0 && ixp_write(fid, buf, len) != len)
			fatal("cannot write file '%s': %s\n", name, ixp_errbuf());
	} while(len > 0);

	free(buf);
}
Пример #5
0
/* Utility Functions */
static void
write_data(IxpCFid *fid, char *name) {
	void *buf;
	int len;

	buf = emalloc(fid->iounit);;
	for(;;) {
		len = read(0, buf, fid->iounit);
		if(len <= 0)
			break;
		if(ixp_write(fid, buf, len) != len)
			fatal("cannot write file %q\n", name);
	}
	free(buf);
}
Пример #6
0
/* ------------------------------------------------------------------------
 * write a buffer to an IXP file
 */
int lixp_write_data (IxpCFid *fid, const char *data, size_t data_len)
{
	size_t left;
	off_t ofs = 0;

	left = data_len;
	while (left) {
		int rc = ixp_write(fid, (char*)data + ofs, left);
		if (rc < 0)
			return rc;

		else if (rc > left)
			return -ENXIO;

		left -= rc;
		ofs += rc;
	}

	return data_len;
}
Пример #7
0
static int
xawrite(int argc, char *argv[]) {
	IxpCFid *fid;
	char *file, *buf, *arg;
	int nbuf, mbuf, len;

	ARGBEGIN{
	default:
		usage();
	}ARGEND;

	file = EARGF(usage());
	fid = ixp_open(client, file, P9_OWRITE);
	if(fid == nil)
		fatal("Can't open file '%s': %s\n", file, ixp_errbuf());

	nbuf = 0;
	mbuf = 128;
	buf = emalloc(mbuf);
	while(argc) {
		arg = ARGF();
		len = strlen(arg);
		if(nbuf + len > mbuf) {
			mbuf <<= 1;
			buf = ixp_erealloc(buf, mbuf);
		}
		memcpy(buf+nbuf, arg, len);
		nbuf += len;
		if(argc)
			buf[nbuf++] = ' ';
	}

	if(ixp_write(fid, buf, nbuf) == -1)
		fatal("cannot write file '%s': %s\n", file, ixp_errbuf());
	return 0;
}