changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: removing libgio, this is not golang mveery >:-(

changeset 5083: 37351cce6c3d
parent 5082: 3f95555d7e8c
child 5085: f1c4958f448a
author: cinap_lenrek@felloff.net
date: Wed, 10 Feb 2016 05:11:11 +0100
files: sys/include/gio.h sys/man/2/gio sys/src/libgio/fd.c sys/src/libgio/mkfile sys/src/libgio/openclose.c sys/src/libgio/readp.c sys/src/libgio/test.c sys/src/libgio/writep.c
description: removing libgio, this is not golang mveery >:-(
     1.1deleted file mode 100644
     1.2--- a/sys/include/gio.h
     1.3+++ /dev/null
     1.4@@ -1,24 +0,0 @@
     1.5-#pragma lib "libgio.a"
     1.6-#pragma src "/sys/src/libgio"
     1.7-
     1.8-typedef struct ReadWriter ReadWriter;
     1.9-
    1.10-struct ReadWriter {
    1.11-	RWLock;
    1.12-	int (*open)(ReadWriter*);
    1.13-	int (*close)(ReadWriter*);
    1.14-	long (*pread)(ReadWriter*, void*, long, vlong);
    1.15-	long (*pwrite)(ReadWriter*, void*, long, vlong);
    1.16-	void *aux;
    1.17-	u64int offset;
    1.18-	u64int length;
    1.19-};
    1.20-
    1.21-ReadWriter* getrdstruct(int);
    1.22-int gopen(ReadWriter*, void*);
    1.23-int gclose(int);
    1.24-long gread(int, void*, long, vlong);
    1.25-long gwrite(int, void*, long, vlong);
    1.26-vlong gseek(int, vlong, int);
    1.27-int fd2gio(int);
    1.28-
     2.1deleted file mode 100644
     2.2--- a/sys/man/2/gio
     2.3+++ /dev/null
     2.4@@ -1,94 +0,0 @@
     2.5-.TH GIO 2
     2.6-.SH NAME
     2.7-gopen, gclose, gseek, gread, gwrite, fd2gio \- Programmable streams
     2.8-.SH SYNOPSIS
     2.9-.B #include <u.h>
    2.10-.br
    2.11-.B #include <libc.h>
    2.12-.br
    2.13-.B #include <gio.h>
    2.14-.PP
    2.15-.ft L
    2.16-.nf
    2.17-typedef struct ReadWriter {
    2.18-	RWLock;
    2.19-	int (*open)(ReadWriter*);
    2.20-	int (*close)(ReadWriter*);
    2.21-	long (*pread)(ReadWriter*, void*, long, vlong);
    2.22-	long (*pwrite)(ReadWriter*, void*, long, vlong);
    2.23-	void *aux;
    2.24-	u64int offset;
    2.25-	u64int length;
    2.26-} ReadWriter;
    2.27-.fi
    2.28-.PP
    2.29-.B
    2.30-int gopen(ReadWriter *r, void *aux)
    2.31-.PP
    2.32-.B
    2.33-int gclose(int gfd)
    2.34-.PP
    2.35-.B
    2.36-vlong gseek(int gfd, vlong offset, int whence)
    2.37-.PP
    2.38-.B
    2.39-long gread(int gfd, void *buf, long nbytes, vlong offset)
    2.40-.PP
    2.41-.B
    2.42-long gwrite(int gfd, void *buf, long nbytes, vlong offset)
    2.43-.PP
    2.44-.B
    2.45-int fd2gio(int fd)
    2.46-.SH DESCRIPTION
    2.47-.I gopen
    2.48-takes a ReadWriter struct and creates a new instance of a gio fd.
    2.49-.I aux
    2.50-is an auxillary argument that may or may not be optional depending on how the gio stream is implemented.
    2.51-.I gclose
    2.52-closes a gio fd and frees any resources allocated to it.
    2.53-.I gseek
    2.54-changes the fd in a similar way to
    2.55-.IR seek (2).
    2.56-.I gread
    2.57-and
    2.58-.I gwrite
    2.59-are the gio equivalents to
    2.60-.IR pread (2)
    2.61-and
    2.62-.IR pwrite (2).
    2.63-They are functionally equivalent and have nearly the same usage.
    2.64-.I fd2gio
    2.65-takes a Plan 9 file descriptor and returns a gio descriptor made from that fd.
    2.66-.SH SOURCE
    2.67-.B /sys/src/libgio
    2.68-.SH NOTES
    2.69-The gio functions automatically lock the ReadWriter struct in use hopefully making things work better with
    2.70-.IR thread (2).
    2.71-.SH BUGS
    2.72-Things get interesting with
    2.73-.IR rfork (2)
    2.74-when you disable shared memory.
    2.75-.br
    2.76-The file descriptor table is poorly implemented.
    2.77-.br
    2.78-You cannot easily mix gio file descriptors with functions that want Plan 9 ones.
    2.79-.br
    2.80-
    2.81-.SH SEE ALSO
    2.82-.IR read (2),
    2.83-.IR seek (2),
    2.84-.IR open (2)
    2.85-.SH DIAGNOSTICS
    2.86-By default, no. Users can have their methods set 
    2.87-.I errstr,
    2.88-and
    2.89-.I gopen,
    2.90-.I gclose,
    2.91-.I gread,
    2.92-and
    2.93-.I gwrite
    2.94-will return -2 if a function pointer is nil.
    2.95-.SH HISTORY
    2.96-First appeared as part of
    2.97-.IR ngfs (8)
    2.98-in September 2015; imported into 9front February 2016.
     3.1deleted file mode 100644
     3.2--- a/sys/src/libgio/fd.c
     3.3+++ /dev/null
     3.4@@ -1,59 +0,0 @@
     3.5-#include <u.h>
     3.6-#include <libc.h>
     3.7-#include <gio.h>
     3.8-
     3.9-int fdopen(ReadWriter*);
    3.10-int fdclose(ReadWriter*);
    3.11-long fdread(ReadWriter*, void*, long, vlong);
    3.12-long fdwrite(ReadWriter*, void*, long, vlong);
    3.13-
    3.14-ReadWriter fdrdwr = {
    3.15-	.open = fdopen,
    3.16-	.close = fdclose,
    3.17-	.pread = fdread,
    3.18-	.pwrite = fdwrite,
    3.19-};
    3.20-
    3.21-int
    3.22-fdopen(ReadWriter *rd)
    3.23-{
    3.24-	int *afd = (int*)rd->aux;
    3.25-
    3.26-	rd->offset = 0;
    3.27-	rd->length = (u64int) seek(*afd, 0, 2);
    3.28-	seek(*afd, 0, 0);
    3.29-	return 0;
    3.30-}
    3.31-
    3.32-int
    3.33-fdclose(ReadWriter *rd)
    3.34-{
    3.35-	void *x = rd->aux;
    3.36-	free(x);
    3.37-	return 0;
    3.38-}
    3.39-
    3.40-long
    3.41-fdread(ReadWriter *rd, void *bf, long len, vlong offset)
    3.42-{
    3.43-	int *afd = (int*)rd->aux;
    3.44-
    3.45-	return pread(*afd, bf, len, offset);
    3.46-}
    3.47-
    3.48-long
    3.49-fdwrite(ReadWriter *rd, void *bf, long len, vlong offset)
    3.50-{
    3.51-	int *afd = (int*)rd->aux;
    3.52-
    3.53-	return pwrite(*afd, bf, len, offset);
    3.54-}
    3.55-
    3.56-int
    3.57-fd2gio(int fd)
    3.58-{
    3.59-	void *x = malloc(sizeof(int));
    3.60-	memcpy(x, &fd, sizeof(int));
    3.61-	return gopen(&fdrdwr, x);
    3.62-}
    3.63-
     4.1deleted file mode 100644
     4.2--- a/sys/src/libgio/mkfile
     4.3+++ /dev/null
     4.4@@ -1,19 +0,0 @@
     4.5-</$objtype/mkfile
     4.6-
     4.7-LIB=/$objtype/lib/libgio.a
     4.8-OFILES=\
     4.9-	fd.$O \
    4.10-	openclose.$O \
    4.11-	readp.$O \
    4.12-	writep.$O \
    4.13-
    4.14-HFILES=\
    4.15-	/sys/include/gio.h\
    4.16-
    4.17-UPDATE=\
    4.18-	mkfile\
    4.19-	$HFILES\
    4.20-	${OFILES:%.$O=%.c}\
    4.21-	${LIB:/$objtype/%=/386/%}\
    4.22-
    4.23-</sys/src/cmd/mksyslib
     5.1deleted file mode 100644
     5.2--- a/sys/src/libgio/openclose.c
     5.3+++ /dev/null
     5.4@@ -1,84 +0,0 @@
     5.5-#include <u.h>
     5.6-#include <libc.h>
     5.7-#include <gio.h>
     5.8-
     5.9-RWLock giolock;
    5.10-ReadWriter *gio_filedes[256];
    5.11-uchar gio_filedes_st[256];
    5.12-
    5.13-int
    5.14-getnext(void)
    5.15-{
    5.16-	int i;
    5.17-	for(i = 0; i < 256; i++)
    5.18-		if(gio_filedes_st[i] == 0)
    5.19-			break;
    5.20-	if(i == 256)
    5.21-		return -1;
    5.22-	return i;
    5.23-}
    5.24-
    5.25-ReadWriter*
    5.26-getrdstruct(int fd)
    5.27-{
    5.28-	rlock(&giolock);
    5.29-	ReadWriter *rval;
    5.30-	if(gio_filedes_st[fd] != 1)
    5.31-		rval = nil;
    5.32-	else
    5.33-		rval = gio_filedes[fd];
    5.34-	runlock(&giolock);
    5.35-	return rval;
    5.36-}
    5.37-
    5.38-int
    5.39-gopen(ReadWriter* rd, void *aux)
    5.40-{
    5.41-	int pfd;
    5.42-	ReadWriter *buf;
    5.43-
    5.44-	wlock(&giolock);
    5.45-	pfd = getnext();
    5.46-	if(pfd == -1){
    5.47-		wunlock(&giolock);
    5.48-		return -1;
    5.49-	}
    5.50-	buf = malloc(sizeof(ReadWriter));
    5.51-	if(buf == nil)
    5.52-		exits("bad malloc");
    5.53-	memcpy(buf, rd, sizeof(ReadWriter));
    5.54-	buf->aux = aux;
    5.55-	buf->offset = 0;
    5.56-	if(buf->open != nil){
    5.57-		if((buf->open(buf)) != 0){
    5.58-			buf->close(buf);
    5.59-			free(buf);
    5.60-			wunlock(&giolock);
    5.61-			return -1;
    5.62-		}
    5.63-	}
    5.64-	gio_filedes[pfd] = buf;
    5.65-	gio_filedes_st[pfd] = 1;
    5.66-	wunlock(&giolock);
    5.67-	return pfd;
    5.68-}
    5.69-
    5.70-int
    5.71-gclose(int fd)
    5.72-{
    5.73-	ReadWriter *bf;
    5.74-	int rval = 0;
    5.75-
    5.76-	if(gio_filedes_st[fd] == 0)
    5.77-		return -1;
    5.78-	wlock(&giolock);
    5.79-	bf = gio_filedes[fd];
    5.80-	if(bf->close != nil)
    5.81-		rval = bf->close(bf);
    5.82-	free(bf);
    5.83-	gio_filedes_st[fd] = 0;
    5.84-	gio_filedes[fd] = nil;
    5.85-	wunlock(&giolock);
    5.86-	return rval;
    5.87-}
    5.88-
     6.1deleted file mode 100644
     6.2--- a/sys/src/libgio/readp.c
     6.3+++ /dev/null
     6.4@@ -1,45 +0,0 @@
     6.5-#include <u.h>
     6.6-#include <libc.h>
     6.7-#include <gio.h>
     6.8-
     6.9-long
    6.10-gread(int fd, void *bf, long len, vlong offset)
    6.11-{
    6.12-	ReadWriter *rd;
    6.13-	long rval = 0;
    6.14-	
    6.15-	rd = getrdstruct(fd);
    6.16-	if(rd == nil)
    6.17-		return -1;
    6.18-	if(rd->pread == nil)
    6.19-		return -2;
    6.20-	rlock(rd);
    6.21-	rval = rd->pread(rd, bf, offset, len);
    6.22-	runlock(rd);
    6.23-	return rval;
    6.24-}
    6.25-
    6.26-vlong
    6.27-gseek(int fd, vlong offset, int type)
    6.28-{
    6.29-	ReadWriter *rd;
    6.30-
    6.31-	rd = getrdstruct(fd);
    6.32-	if(rd == nil)
    6.33-		return -1;
    6.34-	wlock(rd);
    6.35-	switch(type){
    6.36-	case 0:
    6.37-		rd->offset = (u64int)offset;
    6.38-		break;
    6.39-	case 1:
    6.40-		rd->offset = rd->offset + (u64int)offset;
    6.41-		break;
    6.42-	case 2:
    6.43-		rd->offset = rd->length + (u64int)offset;
    6.44-		break;
    6.45-	}
    6.46-	wunlock(rd);
    6.47-	return rd->offset;
    6.48-}
    6.49-
     7.1deleted file mode 100644
     7.2--- a/sys/src/libgio/test.c
     7.3+++ /dev/null
     7.4@@ -1,65 +0,0 @@
     7.5-#include <u.h>
     7.6-#include <libc.h>
     7.7-#include <gio.h>
     7.8-
     7.9-int topen(ReadWriter*);
    7.10-int tclose(ReadWriter*);
    7.11-long tread(ReadWriter*, void*, long, vlong);
    7.12-long twrite(ReadWriter*, void*, long, vlong);
    7.13-
    7.14-ReadWriter tester = {
    7.15-	.open = topen,
    7.16-	.close = tclose,
    7.17-	.pread = tread,
    7.18-	.pwrite = twrite,
    7.19-};
    7.20-
    7.21-void
    7.22-main(int argc, char *argv[])
    7.23-{
    7.24-	int gfd = gopen(&tester, nil);
    7.25-	if(gfd < 0){
    7.26-		print("gio_test: failed to open gio fd\n");
    7.27-		exits("failure");
    7.28-	}
    7.29-	char *test1 = "Hello World!\n";
    7.30-	char test2[256];
    7.31-
    7.32-	gread(gfd, &test2, 256, 23);
    7.33-	gwrite(gfd, test1, sizeof(test1), 8);
    7.34-	print("gio_test: %s\n", test2);
    7.35-	gclose(gfd);
    7.36-	print("gio_test: passed\n");
    7.37-	exits(nil);
    7.38-}
    7.39-
    7.40-int
    7.41-topen(ReadWriter *rd)
    7.42-{
    7.43-	print("gio_test: topen: file opened!\n");
    7.44-	return 0;
    7.45-}
    7.46-
    7.47-int
    7.48-tclose(ReadWriter *rd)
    7.49-{
    7.50-	print("gio_test: tclose: file closed!\n");
    7.51-	return 0;
    7.52-}
    7.53-
    7.54-long
    7.55-tread(ReadWriter *rd, void *bf, long len, vlong offset)
    7.56-{
    7.57-	char *test = "this is a read string!";
    7.58-	memcpy(bf, test, strlen(test)+1);
    7.59-	print("gio_test: tread: len = %ud, offset = %ud\n", len, offset);
    7.60-	return len;
    7.61-}
    7.62-
    7.63-long
    7.64-twrite(ReadWriter *rd, void *bf, long len, vlong offset)
    7.65-{
    7.66-	print("gio_test: twrite: written string: %s\n", bf);
    7.67-	print("gio_test: twrite: len = %ud, offset = %ud\n", len, offset);
    7.68-	return len;
    7.69-}
     8.1deleted file mode 100644
     8.2--- a/sys/src/libgio/writep.c
     8.3+++ /dev/null
     8.4@@ -1,21 +0,0 @@
     8.5-#include <u.h>
     8.6-#include <libc.h>
     8.7-#include <gio.h>
     8.8-
     8.9-long
    8.10-gwrite(int fd, void *buf, long len, vlong offset)
    8.11-{
    8.12-	ReadWriter *rd;
    8.13-	long rval;
    8.14-
    8.15-	rd = getrdstruct(fd);
    8.16-	if(rd == nil)
    8.17-		return -1;
    8.18-	if(rd->pwrite == nil)
    8.19-		return -2;
    8.20-	wlock(rd);
    8.21-	rval = rd->pwrite(rd, buf, len, offset);
    8.22-	wunlock(rd);
    8.23-	return rval;
    8.24-}
    8.25-