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

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


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

char	end[];
static	char	*bloc = { end };

enum
{
	Round	= 7
};

char *
brk(char *p)
{
	uintptr_t bl;

	bl = ((uintptr_t)p + Round) & ~Round;
	if(_BRK_((void*)bl) < 0){
		errno = ENOMEM;
		return (char *)-1;
	}
	bloc = (char*)bl;
	return 0;
}

void *
sbrk(unsigned long n)
{
	uintptr_t bl;

	bl = ((uintptr_t)bloc + Round) & ~Round;
	if(_BRK_((void *)(bloc+n)) < 0){
		errno = ENOMEM;
		return (void *)-1;
	}
	bloc = (char*)bl + n;
	return (void*)bl;
}

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.