9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: steve.simon@snellwilcox.com
To: 9fans@cse.psu.edu
Subject: [9fans] u9fs:  pread pwrite setreuid setregid
Date: Thu,  5 Dec 2002 09:17:15 +0000	[thread overview]
Message-ID: <3736384783@snellwilcox.com> (raw)

[-- Attachment #1: compat.c --]
[-- Type: application/octet-stream, Size: 893 bytes --]

/* 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);
}

[-- Attachment #2: Type: text/plain, Size: 379 bytes --]

Hi,

Getting u9fs to compile under CYGWIN and its adged posix interface
I needed a four of shims functions:

ssize_t pread(int fd, void *p, size_t n, off_t off);
ssize_t pwrite(int fd, const void *p, size_t n, off_t off);
int setreuid(int ruid, int euid);
int setregid(int rgid, int egid);

Just in case this is usefull to somone else it is here attached.


-Steve

             reply	other threads:[~2002-12-05  9:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-05  9:17 steve.simon [this message]
2002-12-05 10:00 ` Lucio De Re
2002-12-05 15:11 Russ Cox
2002-12-05 15:33 ` Lucio De Re

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3736384783@snellwilcox.com \
    --to=steve.simon@snellwilcox.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).