Plan 9 from Bell Labs’s /usr/web/sources/patch/ape-erik/write.c

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


#include <errno.h>
#include <inttypes.h>
#include <unistd.h>
#include "lib.h"
#include "sys9.h"

ssize_t
pwrite(int fd, const void *buf, size_t nbytes, off_t off)
{
	int n;

	if(fd<0 || fd>=OPEN_MAX || !(_fdinfo[fd].flags&FD_ISOPEN)){
		errno = EBADF;
		return -1;
	}
	if(_fdinfo[fd].oflags&O_APPEND)
		_SEEK(fd, 0, 2);
	n = _PWRITE(fd, buf, nbytes, off);
	if(n < 0)
		_syserrno();
	return n;
}

ssize_t
write(int fd, const void *buf, size_t nbytes)
{
	return pwrite(fd, buf, nbytes, -1ll);
}

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].