/** @file
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
NetBSD: findfp.c,v 1.23 2006/10/07 21:40:46 thorpej Exp
findfp.c 8.2 (Berkeley) 1/4/94
**/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#include "namespace.h"
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "reentrant.h"
#include "local.h"
#include "glue.h"
#include <MainData.h>
int __sdidinit;
/* p r w flags file bf lfbsize cookie close */ \
/* read seek write ext up */ \
/* ur ubuf, nbuf lb blksize offset */ \
/* the usual - (stdin + stdout + stderr) */
STDEXT};
#else
#endif
};
void f_prealloc(void);
#ifdef _REENTRANT
#endif
static struct glue *
moreglue(int n)
{
struct glue *g;
FILE *p;
+ n * sizeof(struct __sfileext));
if (g == NULL)
return (NULL);
g->niobs = n;
g->iobs = p;
pext = (void *)(p + n);
while (--n >= 0) {
*p = empty;
_FILEEXT_SETUP(p, pext);
p++;
pext++;
}
return (g);
}
/*
* Find a free FILE for fopen et al.
*/
FILE *
__sfp()
{
int n;
struct glue *g;
if (!__sdidinit)
__sinit();
goto found;
break;
}
return (NULL);
/* fp->_cookie = <any>; */ /* caller sets cookie, _read/_write etc */
return (fp);
}
#if 0
/*
* XXX. Force immediate allocation of internal memory. Not used by stdio,
* but documented historically for certain applications. Bad applications.
*/
void
{
struct glue *g;
int n;
/* void */;
if (n > 0)
}
#endif
/*
* exit() calls _cleanup() through *gMD->cleanup, set whenever we
* open or buffer a file. This chicanery is done so that programs
* that do not use stdio need not link it all in.
*
* The name `_cleanup' is, alas, fairly well known outside stdio.
*/
void
_cleanup( void )
{
/* (void) _fwalk(fclose); */
}
/*
* __sinit() is called whenever stdio's internal variables must be set up.
*/
void
__sinit( void )
{
int i;
for (i = 0; i < FOPEN_MAX - 3; i++)
/* make sure we clean up on exit */
__sdidinit = 1;
}