Back to index

glibc  2.9
mntent.c
Go to the documentation of this file.
00001 /* Utilities for reading/writing fstab, mtab, etc.
00002    Copyright (C) 1995, 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <mntent.h>
00021 #include <stdlib.h>
00022 #include <bits/libc-lock.h>
00023 
00024 /* We don't want to allocate the static buffer all the time since it
00025    is not always used (in fact, rather infrequently).  Accept the
00026    extra cost of a `malloc'.  */
00027 libc_freeres_ptr (static char *getmntent_buffer);
00028 
00029 /* This is the size of the buffer.  This is really big.  */
00030 #define BUFFER_SIZE  4096
00031 
00032 
00033 static void
00034 allocate (void)
00035 {
00036   getmntent_buffer = (char *) malloc (BUFFER_SIZE);
00037 }
00038 
00039 
00040 struct mntent *
00041 getmntent (FILE *stream)
00042 {
00043   static struct mntent m;
00044   __libc_once_define (static, once);
00045   __libc_once (once, allocate);
00046 
00047   if (getmntent_buffer == NULL)
00048     /* If no core is available we don't have a chance to run the
00049        program successfully and so returning NULL is an acceptable
00050        result.  */
00051     return NULL;
00052 
00053   return __getmntent_r (stream, &m, getmntent_buffer, BUFFER_SIZE);
00054 }