Logo ROOT  
Reference Guide
detach.c
Go to the documentation of this file.
1/* @(#)root/clib:$Id$ */
2/* Author: */
3
4/* Finish access to a mmap'd malloc managed region.
5 Copyright 1992 Free Software Foundation, Inc.
6
7 Contributed by Fred Fish at Cygnus Support. fnf@cygnus.com
8
9This file is part of the GNU C Library.
10
11The GNU C Library is free software; you can redistribute it and/or
12modify it under the terms of the GNU Library General Public License as
13published by the Free Software Foundation; either version 2 of the
14License, or (at your option) any later version.
15
16The GNU C Library is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19Library General Public License for more details.
20
21You should have received a copy of the GNU Library General Public
22License along with the GNU C Library; see the file COPYING.LIB. If
23not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24Boston, MA 02111-1307, USA. */
25
26#include <sys/types.h>
27#include <fcntl.h> /* After sys/types.h, at least for dpx/2. */
28#include "mmprivate.h"
29
30/* Terminate access to a mmalloc managed region by unmapping all memory pages
31 associated with the region, and closing the file descriptor if it is one
32 that we opened.
33
34 Returns NULL on success.
35
36 Returns the malloc descriptor on failure, which can subsequently be used
37 for further action, such as obtaining more information about the nature of
38 the failure by examining the preserved errno value.
39
40 Note that the malloc descriptor that we are using is currently located in
41 region we are about to unmap, so we first make a local copy of it on the
42 stack and use the copy. */
43
45{
46 struct mdesc mtemp;
47
48 if (md != NULL)
49 {
50
51 mtemp = *(struct mdesc *) md;
52
53 /* Now unmap all the pages associated with this region by asking for a
54 negative increment equal to the current size of the region. */
55
56 if ((mtemp.morecore (&mtemp, mtemp.base - mtemp.breakval)) == NULL)
57 {
58 /* Update the original malloc descriptor with any changes */
59 /* *(struct mdesc *) md = mtemp; don't update, just unmapped (rdm) */
60 ;
61 }
62 else
63 {
64 if (mtemp.flags & MMALLOC_DEVZERO)
65 {
66#ifndef WIN32
67 close (mtemp.fd);
68#else
69 CloseHandle(mtemp.fd);
70#endif
71 }
72 md = NULL;
73 }
74 }
75
76 return (md);
77}
#define NULL
Definition ZInflate.c:15
PTR mmalloc_detach(PTR md)
Definition detach.c:44
#define PTR
Definition mmalloc.h:29
#define MMALLOC_DEVZERO
Definition mmprivate.h:321
int fd
Definition mmprivate.h:307
unsigned int flags
Definition mmprivate.h:195
char * base
Definition mmprivate.h:284
char * breakval
Definition mmprivate.h:289