Back to index

glibc  2.9
brk.c
Go to the documentation of this file.
00001 /* brk system call for Linux/am33.
00002    Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Alexandre Oliva <aoliva@redhat.com>.
00005    Based on ../i386/brk.c.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public License as
00009    published by the Free Software Foundation; either version 2 of the
00010    License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public
00018    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00019    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020    Boston, MA 02111-1307, USA.  */
00021 
00022 #include <errno.h>
00023 #include <unistd.h>
00024 #include <sysdep.h>
00025 
00026 /* This must be initialized data because commons can't have aliases.  */
00027 void *__curbrk = 0;
00028 
00029 int
00030 __brk (void *addr)
00031 {
00032   void *newbrk;
00033 
00034   newbrk = INLINE_SYSCALL (brk, 1, __ptrvalue (addr));
00035 
00036   __curbrk = newbrk;
00037 
00038   if (newbrk < addr)
00039     {
00040       __set_errno (ENOMEM);
00041       return -1;
00042     }
00043 
00044   return 0;
00045 }
00046 weak_alias (__brk, brk)