Cygwin: fhandler_virtual: move fileid to path_conv member
[newlib-cygwin.git] / libgloss / mep / sbrk.c
blob9ec8676f54315967343cad1763d9bacc0bee9dbe
1 /*
2 * Copyright (c) 2003 Red Hat, Inc. All rights reserved.
4 * This copyrighted material is made available to anyone wishing to use, modify,
5 * copy, or redistribute it subject to the terms and conditions of the BSD
6 * License. This program is distributed in the hope that it will be useful,
7 * but WITHOUT ANY WARRANTY expressed or implied, including the implied
8 * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. A copy
9 * of this license is available at http://www.opensource.org/licenses. Any
10 * Red Hat trademarks that are incorporated in the source code or documentation
11 * are not subject to the BSD License and may only be used or replicated with
12 * the express permission of Red Hat, Inc.
15 #include <errno.h>
17 extern int __heap __far; /* beginning of heap */
18 extern int __heap_end __far; /* if at address 0, use stack pointer as limit */
20 static char *the_break = (char *)(& __heap);
22 int
23 is_addr_0 (int address)
25 return address ? 0 : 1;
28 void *
29 sbrk(int inc)
31 char *current_heap_limit = (char *) (& __heap_end);
33 /* is_addr_0 avoids optimizing out this block. */
34 if (is_addr_0 ((int) current_heap_limit))
36 int something;
37 int margin = 4096;
38 current_heap_limit = (char *) (& something) - margin;
41 if ((the_break + inc) < current_heap_limit)
43 void *rv = (void *) the_break;
44 the_break += inc;
45 return rv;
47 else
49 errno = ENOMEM;
50 return (void *) -1;
54 int
55 brk (void *ptr)
57 the_break = ptr;
58 return 0;