Plan 9 from Bell Labs’s /usr/web/sources/plan9/sys/src/cmd/unix/u9fs/cygwin.c

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


/* compatability layer for u9fs support on CYGWIN */

#include <unistd.h>
#include <errno.h>

ssize_t
pread(int fd, void *p, size_t n, off_t off)
{
	off_t ooff;
	int oerrno;

	if ((ooff  = lseek(fd, off, SEEK_SET)) == -1)
		return -1;

	n = read(fd, p, n);

	oerrno = errno;
	lseek(fd, ooff, SEEK_SET);
	errno = oerrno;

	return n;
}

ssize_t
pwrite(int fd, const void *p, size_t n, off_t off)
{
	off_t ooff;
	int oerrno;

	if ((ooff  = lseek(fd, off, SEEK_SET)) == -1)
		return -1;

	n = write(fd, p, n);

	oerrno = errno;
	lseek(fd, ooff, SEEK_SET);
	errno = oerrno;

	return n;
}

int
setreuid(int ruid, int euid)
{
	if (ruid != -1)
		if (setuid(ruid) == -1)
			return(-1);
	if (euid != -1)
		if (seteuid(euid) == -1)
			return(-1);
}

int
setregid(int rgid, int egid)
{
	if (rgid != -1)
		if (setgid(rgid) == -1)
			return(-1);
	if (egid != -1)
		if (setegid(egid) == -1)
			return(-1);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.