Plan 9 from Bell Labs’s /usr/web/sources/contrib/rsc/linuxemu/libc/linux/9/dirread.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <auth.h>
#include <fcall.h>

#define	N	50
#define	SZ	(N*DIRLEN)

long
dirread(int f, Dir *dbuf, long count)
{
	char *buf;
	int c, n, i, r;

	n = 0;
	buf = malloc(SZ);
	if(buf == nil)
		return -1;
	count = (count/sizeof(Dir)) * DIRLEN;
	while(n < count) {
		c = count - n;
		if(c > SZ)
			c = SZ;
		r = read(f, buf, c);
		if(r == 0)
			break;
		if(r < 0 || r % DIRLEN) {
			free(buf);
			return -1;
		}
		for(i=0; i<r; i+=DIRLEN) {
			convM2D(buf+i, dbuf);
			dbuf++;
		}
		n += r;
		if(r != c)
			break;
	}
	free(buf);
	return (n/DIRLEN) * sizeof(Dir);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].