summaryrefslogtreecommitdiff
path: root/StdLib/LibC/Stdio
diff options
context:
space:
mode:
Diffstat (limited to 'StdLib/LibC/Stdio')
-rw-r--r--StdLib/LibC/Stdio/Stdio.inf3
-rw-r--r--StdLib/LibC/Stdio/clrerr.c8
-rw-r--r--StdLib/LibC/Stdio/fclose.c6
-rw-r--r--StdLib/LibC/Stdio/feof.c7
-rw-r--r--StdLib/LibC/Stdio/ferror.c7
-rw-r--r--StdLib/LibC/Stdio/fflush.c8
-rw-r--r--StdLib/LibC/Stdio/fgetc.c10
-rw-r--r--StdLib/LibC/Stdio/fgetpos.c9
-rw-r--r--StdLib/LibC/Stdio/fgets.c9
-rw-r--r--StdLib/LibC/Stdio/fgetstr.c33
-rw-r--r--StdLib/LibC/Stdio/fgetwc.c17
-rw-r--r--StdLib/LibC/Stdio/fgetws.c23
-rw-r--r--StdLib/LibC/Stdio/fileno.c27
-rw-r--r--StdLib/LibC/Stdio/fparseln.c22
-rw-r--r--StdLib/LibC/Stdio/fprintf.c8
-rw-r--r--StdLib/LibC/Stdio/fpurge.c27
-rw-r--r--StdLib/LibC/Stdio/fputc.c10
-rw-r--r--StdLib/LibC/Stdio/fputs.c8
-rw-r--r--StdLib/LibC/Stdio/fputwc.c26
-rw-r--r--StdLib/LibC/Stdio/fputws.c21
-rw-r--r--StdLib/LibC/Stdio/fread.c8
-rw-r--r--StdLib/LibC/Stdio/freopen.c8
-rw-r--r--StdLib/LibC/Stdio/fseeko.c20
-rw-r--r--StdLib/LibC/Stdio/fvwrite.c27
-rw-r--r--StdLib/LibC/Stdio/fwide.c23
-rw-r--r--StdLib/LibC/Stdio/fwrite.c9
-rw-r--r--StdLib/LibC/Stdio/getc.c12
-rw-r--r--StdLib/LibC/Stdio/makebuf.c9
-rw-r--r--StdLib/LibC/Stdio/putc.c12
-rw-r--r--StdLib/LibC/Stdio/refill.c35
-rw-r--r--StdLib/LibC/Stdio/rewind.c6
-rw-r--r--StdLib/LibC/Stdio/rget.c6
-rw-r--r--StdLib/LibC/Stdio/setvbuf.c8
-rw-r--r--StdLib/LibC/Stdio/stdio.c20
-rw-r--r--StdLib/LibC/Stdio/tmpfile.c8
-rw-r--r--StdLib/LibC/Stdio/ungetc.c12
-rw-r--r--StdLib/LibC/Stdio/vfscanf.c29
-rw-r--r--StdLib/LibC/Stdio/vfwprintf.c16
-rw-r--r--StdLib/LibC/Stdio/vsnprintf.c8
-rw-r--r--StdLib/LibC/Stdio/wbuf.c27
-rw-r--r--StdLib/LibC/Stdio/wsetup.c27
41 files changed, 452 insertions, 167 deletions
diff --git a/StdLib/LibC/Stdio/Stdio.inf b/StdLib/LibC/Stdio/Stdio.inf
index 56eaae3291..9d2adef1f6 100644
--- a/StdLib/LibC/Stdio/Stdio.inf
+++ b/StdLib/LibC/Stdio/Stdio.inf
@@ -70,6 +70,9 @@
vprintf.c #
vsprintf.c #
+ snprintf.c
+ vsnprintf.c
+
# Wide character functions
fgetwc.c #
fgetws.c #
diff --git a/StdLib/LibC/Stdio/clrerr.c b/StdLib/LibC/Stdio/clrerr.c
index bda0d04ce8..469dc8c96a 100644
--- a/StdLib/LibC/Stdio/clrerr.c
+++ b/StdLib/LibC/Stdio/clrerr.c
@@ -1,7 +1,7 @@
/** @file
Implementation of clearerr as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
@@ -47,6 +47,7 @@
#include <assert.h>
#include <stdio.h>
+#include <errno.h>
#include "reentrant.h"
#include "local.h"
@@ -55,9 +56,10 @@
void
clearerr(FILE *fp)
{
- //_DIAGASSERT(fp != NULL);
-
+ _DIAGASSERT(fp != NULL);
+ if(fp != NULL) {
FLOCKFILE(fp);
__sclearerr(fp);
FUNLOCKFILE(fp);
+ }
}
diff --git a/StdLib/LibC/Stdio/fclose.c b/StdLib/LibC/Stdio/fclose.c
index 3745e20f94..1ce28bcab4 100644
--- a/StdLib/LibC/Stdio/fclose.c
+++ b/StdLib/LibC/Stdio/fclose.c
@@ -1,7 +1,7 @@
/** @file
Implementation of fclose as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
@@ -59,6 +59,10 @@ fclose(FILE *fp)
int r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if (fp->_flags == 0) { /* not open! */
errno = EBADF;
diff --git a/StdLib/LibC/Stdio/feof.c b/StdLib/LibC/Stdio/feof.c
index 70b5e5090e..7850e39268 100644
--- a/StdLib/LibC/Stdio/feof.c
+++ b/StdLib/LibC/Stdio/feof.c
@@ -2,7 +2,7 @@
Implementation of a subroutine version of the macro feof,
as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
@@ -48,6 +48,7 @@
#include <assert.h>
#include <stdio.h>
+#include <errno.h>
#include "reentrant.h"
#include "local.h"
@@ -59,6 +60,10 @@ feof(FILE *fp)
int r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
FLOCKFILE(fp);
r = __sfeof(fp);
diff --git a/StdLib/LibC/Stdio/ferror.c b/StdLib/LibC/Stdio/ferror.c
index 5641b48038..4a3996fadd 100644
--- a/StdLib/LibC/Stdio/ferror.c
+++ b/StdLib/LibC/Stdio/ferror.c
@@ -2,7 +2,7 @@
Implementation of a subroutine version of the macro ferror,
as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
@@ -48,6 +48,7 @@
#include <assert.h>
#include <stdio.h>
+#include <errno.h>
#include "reentrant.h"
#include "local.h"
@@ -59,6 +60,10 @@ ferror(FILE *fp)
int r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
FLOCKFILE(fp);
r = __sferror(fp);
diff --git a/StdLib/LibC/Stdio/fflush.c b/StdLib/LibC/Stdio/fflush.c
index fd21e37a13..5a4d62468e 100644
--- a/StdLib/LibC/Stdio/fflush.c
+++ b/StdLib/LibC/Stdio/fflush.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fflush as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -87,6 +87,10 @@ __sflush(FILE *fp)
int t;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
t = fp->_flags;
if ((t & __SWR) == 0)
diff --git a/StdLib/LibC/Stdio/fgetc.c b/StdLib/LibC/Stdio/fgetc.c
index b6e1a258ba..aee896fea5 100644
--- a/StdLib/LibC/Stdio/fgetc.c
+++ b/StdLib/LibC/Stdio/fgetc.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fgetc as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -58,8 +58,14 @@ fgetc(FILE *fp)
_DIAGASSERT(fp != NULL);
+ if(fp != NULL) {
FLOCKFILE(fp);
r = __sgetc(fp);
FUNLOCKFILE(fp);
+ }
+ else {
+ r = EOF;
+ errno = ENOSTR;
+ }
return r;
}
diff --git a/StdLib/LibC/Stdio/fgetpos.c b/StdLib/LibC/Stdio/fgetpos.c
index f076718278..61d6f756d0 100644
--- a/StdLib/LibC/Stdio/fgetpos.c
+++ b/StdLib/LibC/Stdio/fgetpos.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fgetpos as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -56,5 +56,10 @@ fgetpos(FILE *fp, fpos_t *pos)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(pos != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
return((*pos = (off_t)ftello(fp)) == (off_t)-1);
}
diff --git a/StdLib/LibC/Stdio/fgets.c b/StdLib/LibC/Stdio/fgets.c
index cf107ab867..cb07154ada 100644
--- a/StdLib/LibC/Stdio/fgets.c
+++ b/StdLib/LibC/Stdio/fgets.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fgets as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -48,6 +48,7 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include "reentrant.h"
#include "local.h"
@@ -65,8 +66,10 @@ fgets(char *buf, int n, FILE *fp)
_DIAGASSERT(buf != NULL);
_DIAGASSERT(fp != NULL);
- if (n <= 0) /* sanity check */
+ if ((fp == NULL) || (n <= 0)) { /* sanity check */
+ errno = EINVAL;
return (NULL);
+ }
FLOCKFILE(fp);
_SET_ORIENTATION(fp, -1);
diff --git a/StdLib/LibC/Stdio/fgetstr.c b/StdLib/LibC/Stdio/fgetstr.c
index 7364d3b891..9e898f3263 100644
--- a/StdLib/LibC/Stdio/fgetstr.c
+++ b/StdLib/LibC/Stdio/fgetstr.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,20 +37,20 @@
* 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: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $
+ fgetline.c 8.1 (Berkeley) 6/4/93
+*/
+
+/*-
*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)fgetline.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: fgetstr.c,v 1.4 2006/11/24 19:46:58 christos Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -66,6 +73,10 @@ __slbexpand(FILE *fp, size_t newsize)
++newsize;
#endif
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
if ((size_t)fp->_lb._size >= newsize)
return (0);
@@ -92,6 +103,10 @@ __fgetstr(FILE *fp, size_t *lenp, int sep)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(lenp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
/* make sure there is input */
if (fp->_r <= 0 && __srefill(fp)) {
diff --git a/StdLib/LibC/Stdio/fgetwc.c b/StdLib/LibC/Stdio/fgetwc.c
index 548192390d..f2159d7e41 100644
--- a/StdLib/LibC/Stdio/fgetwc.c
+++ b/StdLib/LibC/Stdio/fgetwc.c
@@ -1,4 +1,13 @@
/*-
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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)2001 Citrus Project,
* All rights reserved.
*
@@ -46,6 +55,10 @@ __fgetwc_unlock(FILE *fp)
size_t size;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = ENOSTR;
+ return WEOF;
+ }
_SET_ORIENTATION(fp, 1);
wcio = WCIO_GET(fp);
@@ -91,6 +104,10 @@ fgetwc(FILE *fp)
wint_t r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (WEOF);
+ }
FLOCKFILE(fp);
r = __fgetwc_unlock(fp);
diff --git a/StdLib/LibC/Stdio/fgetws.c b/StdLib/LibC/Stdio/fgetws.c
index 0113557965..44a885ac54 100644
--- a/StdLib/LibC/Stdio/fgetws.c
+++ b/StdLib/LibC/Stdio/fgetws.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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) 2002 Tim J. Robbins.
* All rights reserved.
*
@@ -27,13 +34,11 @@
*
* Original version ID:
* FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp
- *
- */
+
+ $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIB_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $");
-#endif
#include <assert.h>
#include <errno.h>
@@ -54,6 +59,10 @@ fgetws(
_DIAGASSERT(fp != NULL);
_DIAGASSERT(ws != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
FLOCKFILE(fp);
_SET_ORIENTATION(fp, 1);
diff --git a/StdLib/LibC/Stdio/fileno.c b/StdLib/LibC/Stdio/fileno.c
index b9468c7cfc..779cbd8682 100644
--- a/StdLib/LibC/Stdio/fileno.c
+++ b/StdLib/LibC/Stdio/fileno.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,16 +37,12 @@
* 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: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp
+ fileno.c 8.1 (Berkeley) 6/4/93
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)fileno.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: fileno.c,v 1.12 2004/05/09 17:27:53 kleink Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
@@ -63,6 +66,10 @@ _fileno(fp)
int r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
FLOCKFILE(fp);
r = __sfileno(fp);
diff --git a/StdLib/LibC/Stdio/fparseln.c b/StdLib/LibC/Stdio/fparseln.c
index c1ce12be2e..be1a42fb6b 100644
--- a/StdLib/LibC/Stdio/fparseln.c
+++ b/StdLib/LibC/Stdio/fparseln.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $ */
-
/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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) 1997 Christos Zoulas. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,12 +34,11 @@
* 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: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $");
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@@ -107,6 +113,10 @@ fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
char esc, con, nl, com;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
len = 0;
buf = NULL;
diff --git a/StdLib/LibC/Stdio/fprintf.c b/StdLib/LibC/Stdio/fprintf.c
index ba6ec0c22e..7134c5c5e6 100644
--- a/StdLib/LibC/Stdio/fprintf.c
+++ b/StdLib/LibC/Stdio/fprintf.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fprintf as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -58,6 +58,10 @@ fprintf(FILE *fp, const char *fmt, ...)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(fmt != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
va_start(ap, fmt);
ret = vfprintf(fp, fmt, ap);
diff --git a/StdLib/LibC/Stdio/fpurge.c b/StdLib/LibC/Stdio/fpurge.c
index cc649eee49..48c5482a7c 100644
--- a/StdLib/LibC/Stdio/fpurge.c
+++ b/StdLib/LibC/Stdio/fpurge.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,16 +37,12 @@
* 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: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp
+ fpurge.c 8.1 (Berkeley) 6/4/93
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: fpurge.c,v 1.13 2003/08/07 16:43:24 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
@@ -59,6 +62,10 @@ fpurge(fp)
{
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if (fp->_flags == 0) {
errno = EBADF;
diff --git a/StdLib/LibC/Stdio/fputc.c b/StdLib/LibC/Stdio/fputc.c
index b9ae5aa828..a7dfdef485 100644
--- a/StdLib/LibC/Stdio/fputc.c
+++ b/StdLib/LibC/Stdio/fputc.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fputc as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -58,8 +58,14 @@ fputc(int c, FILE *fp)
_DIAGASSERT(fp != NULL);
+ if(fp != NULL) {
FLOCKFILE(fp);
r = __sputc(c, fp);
FUNLOCKFILE(fp);
+ }
+ else {
+ r = EOF;
+ errno = ENOSTR;
+ }
return r;
}
diff --git a/StdLib/LibC/Stdio/fputs.c b/StdLib/LibC/Stdio/fputs.c
index 081ee1a099..56e622276a 100644
--- a/StdLib/LibC/Stdio/fputs.c
+++ b/StdLib/LibC/Stdio/fputs.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fputs as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -65,6 +65,10 @@ fputs(const char *s, FILE *fp)
_DIAGASSERT(s != NULL);
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if (s == NULL)
s = "(null)";
diff --git a/StdLib/LibC/Stdio/fputwc.c b/StdLib/LibC/Stdio/fputwc.c
index 49f6702227..8bbd407362 100644
--- a/StdLib/LibC/Stdio/fputwc.c
+++ b/StdLib/LibC/Stdio/fputwc.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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)2001 Citrus Project,
* All rights reserved.
*
@@ -26,12 +33,11 @@
* SUCH DAMAGE.
*
* $Citrus$
- */
+
+NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");
-#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
@@ -53,6 +59,10 @@ __fputwc_unlock(wchar_t wc, FILE *fp)
struct __siov iov;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (WEOF);
+ }
/* LINTED we don't play with buf */
iov.iov_base = (void *)buf;
@@ -91,6 +101,10 @@ fputwc(wchar_t wc, FILE *fp)
wint_t r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (WEOF);
+ }
FLOCKFILE(fp);
r = __fputwc_unlock(wc, fp);
diff --git a/StdLib/LibC/Stdio/fputws.c b/StdLib/LibC/Stdio/fputws.c
index ce373bb402..ddfc5ddd30 100644
--- a/StdLib/LibC/Stdio/fputws.c
+++ b/StdLib/LibC/Stdio/fputws.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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) 2002 Tim J. Robbins.
* All rights reserved.
*
@@ -27,12 +34,10 @@
*
* Original version ID:
* FreeBSD: src/lib/libc/stdio/fputws.c,v 1.4 2002/09/20 13:25:40 tjr Exp
- */
+ NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fputws.c,v 1.1 2003/03/07 07:11:37 tshiozak Exp $");
-#endif
#include <assert.h>
#include <errno.h>
@@ -49,6 +54,10 @@ fputws(
{
_DIAGASSERT(fp != NULL);
_DIAGASSERT(ws != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
FLOCKFILE(fp);
_SET_ORIENTATION(fp, 1);
diff --git a/StdLib/LibC/Stdio/fread.c b/StdLib/LibC/Stdio/fread.c
index 21013d7ff4..7693ab3c06 100644
--- a/StdLib/LibC/Stdio/fread.c
+++ b/StdLib/LibC/Stdio/fread.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fread as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -61,6 +61,10 @@ fread(void *buf, size_t size, size_t count, FILE *fp)
size_t total;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (0);
+ }
/*
* The ANSI standard requires a return value of 0 for a count
* or a size of 0. Whilst ANSI imposes no such requirements on
diff --git a/StdLib/LibC/Stdio/freopen.c b/StdLib/LibC/Stdio/freopen.c
index 186ab9ad66..4d34497317 100644
--- a/StdLib/LibC/Stdio/freopen.c
+++ b/StdLib/LibC/Stdio/freopen.c
@@ -1,11 +1,11 @@
/** @file
Implementation of freopen as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -73,6 +73,10 @@ freopen(const char *file, const char *mode, FILE *fp)
_DIAGASSERT(file != NULL);
_DIAGASSERT(mode != NULL);
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
if ((flags = __sflags(mode, &oflags)) == 0) {
(void) fclose(fp);
diff --git a/StdLib/LibC/Stdio/fseeko.c b/StdLib/LibC/Stdio/fseeko.c
index 3c406eaec8..7fc7e42661 100644
--- a/StdLib/LibC/Stdio/fseeko.c
+++ b/StdLib/LibC/Stdio/fseeko.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,15 +37,14 @@
* 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: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp
*/
//#include <Uefi.h> // REMOVE, For DEBUG only
//#include <Library/UefiLib.h> // REMOVE, For DEBUG only
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fseeko.c,v 1.5 2005/03/04 16:04:58 dsl Exp $");
-#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <sys/types.h>
@@ -72,6 +78,10 @@ fseeko(FILE *fp, off_t offset, int whence)
int havepos;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
#ifdef __GNUC__
/* This outrageous construct just to shut up a GCC warning. */
diff --git a/StdLib/LibC/Stdio/fvwrite.c b/StdLib/LibC/Stdio/fvwrite.c
index fcbb256067..12773eff68 100644
--- a/StdLib/LibC/Stdio/fvwrite.c
+++ b/StdLib/LibC/Stdio/fvwrite.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,16 +37,12 @@
* 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: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp
+ fvwrite.c 8.1 (Berkeley) 6/4/93
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)fvwrite.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: fvwrite.c,v 1.16.2.1 2007/05/07 19:49:09 pavel Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
@@ -68,6 +71,10 @@ __sfvwrite(FILE *fp, struct __suio *uio)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(uio != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if ((len = uio->uio_resid) == 0)
return (0);
diff --git a/StdLib/LibC/Stdio/fwide.c b/StdLib/LibC/Stdio/fwide.c
index b89b7a3811..4ba1423eb2 100644
--- a/StdLib/LibC/Stdio/fwide.c
+++ b/StdLib/LibC/Stdio/fwide.c
@@ -1,6 +1,13 @@
-/* $NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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)2001 Citrus Project,
* All rights reserved.
*
@@ -26,14 +33,14 @@
* SUCH DAMAGE.
*
* $Citrus$
- */
+
+ NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: fwide.c,v 1.3 2005/06/12 05:21:27 lukem Exp $");
-#endif /* LIBC_SCCS and not lint */
#include <assert.h>
+#include <errno.h>
#include <stdio.h>
#include <wchar.h>
#include "reentrant.h"
@@ -45,6 +52,10 @@ fwide(FILE *fp, int mode)
struct wchar_io_data *wcio;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (0);
+ }
/*
* this implementation use only -1, 0, 1
diff --git a/StdLib/LibC/Stdio/fwrite.c b/StdLib/LibC/Stdio/fwrite.c
index 9416e67aea..c998e272b6 100644
--- a/StdLib/LibC/Stdio/fwrite.c
+++ b/StdLib/LibC/Stdio/fwrite.c
@@ -1,11 +1,11 @@
/** @file
Implementation of fwrite as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -64,6 +64,11 @@ fwrite(const void *buf, size_t size, size_t count, FILE *fp)
struct __siov iov;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (0);
+ }
+
/*
* SUSv2 requires a return value of 0 for a count or a size of 0.
*/
diff --git a/StdLib/LibC/Stdio/getc.c b/StdLib/LibC/Stdio/getc.c
index c0f367b892..755251eef7 100644
--- a/StdLib/LibC/Stdio/getc.c
+++ b/StdLib/LibC/Stdio/getc.c
@@ -1,11 +1,11 @@
/** @file
Implementation of getc as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -63,6 +63,10 @@ getc(FILE *fp)
int r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = ENOSTR;
+ return (EOF);
+ }
FLOCKFILE(fp);
r = __sgetc(fp);
@@ -75,6 +79,10 @@ getc_unlocked(FILE *fp)
{
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = ENOSTR;
+ return EOF;
+ }
return (__sgetc(fp));
}
diff --git a/StdLib/LibC/Stdio/makebuf.c b/StdLib/LibC/Stdio/makebuf.c
index 75c475c3a5..4e69be1275 100644
--- a/StdLib/LibC/Stdio/makebuf.c
+++ b/StdLib/LibC/Stdio/makebuf.c
@@ -1,11 +1,11 @@
/** @file
Implementation of internal file buffer allocation functions.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -74,6 +74,7 @@ __smakebuf(FILE *fp)
_DIAGASSERT(fp != NULL);
+ if (fp != NULL) {
if (fp->_flags & __SNBF) {
fp->_bf._base = fp->_p = fp->_nbuf;
fp->_bf._size = 1;
@@ -93,6 +94,7 @@ __smakebuf(FILE *fp)
if (couldbetty || isatty(fp->_file))
flags |= __SLBF;
fp->_flags |= flags;
+ }
}
/*
@@ -106,6 +108,9 @@ __swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(bufsize != NULL);
_DIAGASSERT(couldbetty != NULL);
+ if(fp == NULL) {
+ return (__SNPT);
+ }
if (fp->_file < 0 || fstat(fp->_file, &st) < 0) {
*couldbetty = 0;
diff --git a/StdLib/LibC/Stdio/putc.c b/StdLib/LibC/Stdio/putc.c
index 891e747a56..25f49f8646 100644
--- a/StdLib/LibC/Stdio/putc.c
+++ b/StdLib/LibC/Stdio/putc.c
@@ -2,11 +2,11 @@
Implementation of a subroutine version of the macro putc,
as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -64,6 +64,10 @@ putc(int c, FILE *fp)
int r;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
FLOCKFILE(fp);
r = __sputc(c, fp);
@@ -75,6 +79,10 @@ int
putc_unlocked(int c, FILE *fp)
{
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
return (__sputc(c, fp));
}
diff --git a/StdLib/LibC/Stdio/refill.c b/StdLib/LibC/Stdio/refill.c
index e2d162375b..953e8f674a 100644
--- a/StdLib/LibC/Stdio/refill.c
+++ b/StdLib/LibC/Stdio/refill.c
@@ -1,6 +1,13 @@
-/* $NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,19 +37,15 @@
* 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: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp
+ refill.c 8.1 (Berkeley) 6/4/93
+*/
#include <Uefi.h> // REMOVE, For DEBUG only
#include <Library/UefiLib.h> // REMOVE, For DEBUG only
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)refill.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: refill.c,v 1.13 2003/08/07 16:43:30 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
@@ -61,7 +64,11 @@ static int
lflush(FILE *fp)
{
- //_DIAGASSERT(fp != NULL);
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if ((fp->_flags & (__SLBF|__SWR)) == (__SLBF|__SWR))
return (__sflush(fp));
@@ -76,7 +83,11 @@ int
__srefill(FILE *fp)
{
- //_DIAGASSERT(fp != NULL);
+ _DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
/* make sure stdio is set up */
if (!__sdidinit)
diff --git a/StdLib/LibC/Stdio/rewind.c b/StdLib/LibC/Stdio/rewind.c
index 4f2ab041a2..5d1042152b 100644
--- a/StdLib/LibC/Stdio/rewind.c
+++ b/StdLib/LibC/Stdio/rewind.c
@@ -1,11 +1,11 @@
/** @file
Implementation of rewind as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -56,8 +56,10 @@ rewind(FILE *fp)
{
_DIAGASSERT(fp != NULL);
+ if(fp != NULL) {
FLOCKFILE(fp);
(void) fseek(fp, 0L, SEEK_SET);
__sclearerr(fp);
FUNLOCKFILE(fp);
+ }
}
diff --git a/StdLib/LibC/Stdio/rget.c b/StdLib/LibC/Stdio/rget.c
index ba97ac201b..74f73dcac4 100644
--- a/StdLib/LibC/Stdio/rget.c
+++ b/StdLib/LibC/Stdio/rget.c
@@ -1,11 +1,11 @@
/** @file
Internal function to refill the buffer when getc() empties it.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -61,10 +61,12 @@ __srget(FILE *fp)
{
_DIAGASSERT(fp != NULL);
+ if(fp != NULL) {
_SET_ORIENTATION(fp, -1);
if (__srefill(fp) == 0) {
fp->_r--;
return (*fp->_p++);
+ }
}
return (EOF);
}
diff --git a/StdLib/LibC/Stdio/setvbuf.c b/StdLib/LibC/Stdio/setvbuf.c
index 3ea96ff6da..9e01ea9dc1 100644
--- a/StdLib/LibC/Stdio/setvbuf.c
+++ b/StdLib/LibC/Stdio/setvbuf.c
@@ -1,11 +1,11 @@
/** @file
Implementation of setvbuf as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -67,6 +67,10 @@ setvbuf(FILE *fp, char *buf, int mode, size_t size)
_DIAGASSERT(fp != NULL);
/* buf may be NULL */
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
/*
* Verify arguments. The `int' limit on `size' is due to this
diff --git a/StdLib/LibC/Stdio/stdio.c b/StdLib/LibC/Stdio/stdio.c
index 005a4388df..de8963e574 100644
--- a/StdLib/LibC/Stdio/stdio.c
+++ b/StdLib/LibC/Stdio/stdio.c
@@ -2,11 +2,11 @@
Small standard I/O/seek/close functions.
These maintain the `known seek offset' for seek optimisation.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -65,6 +65,10 @@ __sread(void *cookie, char *buf, int n)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(buf != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
ret = (int)read(fp->_file, buf, (size_t)n);
/* if the read succeeded, update the current offset */
@@ -82,6 +86,10 @@ __swrite(void *cookie, char const *buf, int n)
_DIAGASSERT(cookie != NULL);
_DIAGASSERT(buf != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if (fp->_flags & __SAPP)
(void) lseek(fp->_file, (off_t)0, SEEK_END);
@@ -96,6 +104,10 @@ __sseek(void *cookie, fpos_t offset, int whence)
off_t ret;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
ret = lseek(fp->_file, (off_t)offset, whence);
if (ret == -1L)
@@ -112,6 +124,10 @@ __sclose(void *cookie)
{
_DIAGASSERT(cookie != NULL);
+ if(cookie == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
return (close(((FILE *)cookie)->_file));
}
diff --git a/StdLib/LibC/Stdio/tmpfile.c b/StdLib/LibC/Stdio/tmpfile.c
index bfcf77c49d..97040d58f2 100644
--- a/StdLib/LibC/Stdio/tmpfile.c
+++ b/StdLib/LibC/Stdio/tmpfile.c
@@ -68,8 +68,12 @@ tmpfile()
//(void)sigprocmask(SIG_BLOCK, &set, &oset);
fd = mkstemp(buf);
- if (fd != -1)
- (void)unlink(buf);
+ if (fd != -1) {
+ /* Changed from unlink(buf) because of differences between the behavior
+ of Unix and UEFI file systems.
+ */
+ (void)DeleteOnClose(fd);
+ }
//(void)sigprocmask(SIG_SETMASK, &oset, NULL);
diff --git a/StdLib/LibC/Stdio/ungetc.c b/StdLib/LibC/Stdio/ungetc.c
index e9d3807fcb..d8e1f3afc6 100644
--- a/StdLib/LibC/Stdio/ungetc.c
+++ b/StdLib/LibC/Stdio/ungetc.c
@@ -1,11 +1,11 @@
/** @file
Implementation of ungetc as declared in <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -67,6 +67,10 @@ __submore(FILE *fp)
unsigned char *p;
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if (_UB(fp)._base == fp->_ubuf) {
/*
@@ -98,6 +102,10 @@ int
ungetc(int c, FILE *fp)
{
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if (c == EOF)
return (EOF);
diff --git a/StdLib/LibC/Stdio/vfscanf.c b/StdLib/LibC/Stdio/vfscanf.c
index 724fd2a747..861fb53301 100644
--- a/StdLib/LibC/Stdio/vfscanf.c
+++ b/StdLib/LibC/Stdio/vfscanf.c
@@ -1,11 +1,11 @@
/** @file
Implementation of scanf internals for <stdio.h>.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 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
- http://opensource.org/licenses/bsd-license.php.
+ http://opensource.org/licenses/bsd-license.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
@@ -44,14 +44,12 @@
FreeBSD: src/lib/libc/stdio/vfscanf.c,v 1.41 2007/01/09 00:28:07 imp Exp
vfscanf.c 8.1 (Berkeley) 6/4/93
**/
-//#include <Uefi.h> // REMOVE, For DEBUG only
-//#include <Library/UefiLib.h> // REMOVE, For DEBUG only
-
#include <LibConfig.h>
#include "namespace.h"
#include <assert.h>
#include <ctype.h>
+#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@@ -142,6 +140,10 @@ __svfscanf(FILE *fp, char const *fmt0, va_list ap)
{
int ret;
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
FLOCKFILE(fp);
ret = __svfscanf_unlocked(fp, fmt0, ap);
FUNLOCKFILE(fp);
@@ -178,6 +180,10 @@ __svfscanf_unlocked(FILE *fp, const char *fmt0, va_list ap)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(fmt0 != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
_SET_ORIENTATION(fp, -1);
@@ -837,12 +843,12 @@ literal:
goto match_failure;
if ((flags & SUPPRESS) == 0) {
if (flags & LONGDBL) {
-/*dvm*/ long double **mp = (long double **)ap;
+ long double **mp = (long double **)ap;
long double res = strtold(buf, &p);
-/*dvm*/ *(*mp) = res;
-/*dvm*/ ap += sizeof(long double *);
-/*dvm*/ //*va_arg(ap, long double *) = res;
+ *(*mp) = res;
+ ap += sizeof(long double *);
+/*???*/ //*va_arg(ap, long double *) = res;
} else if (flags & LONG) {
double res = strtod(buf, &p);
*va_arg(ap, double *) = res;
@@ -989,6 +995,11 @@ parsefloat(FILE *fp, char *buf, char *end)
char decpt = *localeconv()->decimal_point;
_Bool gotmantdig = 0, ishex = 0;
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
+
/*
* We set commit = p whenever the string we have read so far
* constitutes a valid representation of a floating point
diff --git a/StdLib/LibC/Stdio/vfwprintf.c b/StdLib/LibC/Stdio/vfwprintf.c
index bf31ddb664..3c5332ac4a 100644
--- a/StdLib/LibC/Stdio/vfwprintf.c
+++ b/StdLib/LibC/Stdio/vfwprintf.c
@@ -164,6 +164,10 @@ __sbprintf(FILE *fp, const CHAR_T *fmt, va_list ap)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(fmt != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
_FILEEXT_SETUP(&fake, &fakeext);
@@ -229,6 +233,10 @@ __sprint(FILE *fp, struct __suio *uio)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(uio != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
if (uio->uio_resid == 0) {
uio->uio_iovcnt = 0;
@@ -544,6 +552,10 @@ WDECL(vf,printf)(FILE * __restrict fp, const CHAR_T * __restrict fmt0, va_list a
{
int ret;
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
FLOCKFILE(fp);
ret = WDECL(__vf,printf_unlocked)(fp, fmt0, ap);
FUNLOCKFILE(fp);
@@ -801,6 +813,10 @@ WDECL(__vf,printf_unlocked)(FILE *fp, const CHAR_T *fmt0, va_list ap)
_DIAGASSERT(fp != NULL);
_DIAGASSERT(fmt0 != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
_SET_ORIENTATION(fp, -1);
diff --git a/StdLib/LibC/Stdio/vsnprintf.c b/StdLib/LibC/Stdio/vsnprintf.c
index b2a2f63a91..23385ba0d8 100644
--- a/StdLib/LibC/Stdio/vsnprintf.c
+++ b/StdLib/LibC/Stdio/vsnprintf.c
@@ -54,11 +54,7 @@ __weak_alias(vsnprintf,_vsnprintf)
#endif
int
-vsnprintf(str, n, fmt, ap)
- char *str;
- size_t n;
- const char *fmt;
- _BSD_VA_LIST_ ap;
+vsnprintf(char *str, size_t n, const char *fmt, _BSD_VA_LIST_ ap)
{
int ret;
FILE f;
@@ -81,7 +77,7 @@ vsnprintf(str, n, fmt, ap)
f._bf._size = f._w = 0;
} else {
f._bf._base = f._p = (unsigned char *)str;
- f._bf._size = f._w = n - 1;
+ f._bf._size = f._w = (int)(n - 1);
}
ret = __vfprintf_unlocked(&f, fmt, ap);
*f._p = 0;
diff --git a/StdLib/LibC/Stdio/wbuf.c b/StdLib/LibC/Stdio/wbuf.c
index 8482a18e87..888be1ea3b 100644
--- a/StdLib/LibC/Stdio/wbuf.c
+++ b/StdLib/LibC/Stdio/wbuf.c
@@ -1,6 +1,13 @@
-/* $NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,16 +37,12 @@
* 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: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp
+ wbuf.c 8.1 (Berkeley) 6/4/93
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)wbuf.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: wbuf.c,v 1.13 2003/08/07 16:43:35 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
@@ -58,6 +61,10 @@ __swbuf(int c, FILE *fp)
int n;
//_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (EOF);
+ }
_SET_ORIENTATION(fp, -1);
diff --git a/StdLib/LibC/Stdio/wsetup.c b/StdLib/LibC/Stdio/wsetup.c
index c1077bc9df..b8fc06449e 100644
--- a/StdLib/LibC/Stdio/wsetup.c
+++ b/StdLib/LibC/Stdio/wsetup.c
@@ -1,6 +1,13 @@
-/* $NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $ */
+/*
+ Copyright (c) 2010 - 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
+ http://opensource.org/licenses/bsd-license.
+
+ 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.
*
@@ -30,16 +37,12 @@
* 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: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp
+ wsetup.c 8.1 (Berkeley) 6/4/93
+*/
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-#if 0
-static char sccsid[] = "@(#)wsetup.c 8.1 (Berkeley) 6/4/93";
-#else
-__RCSID("$NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp $");
-#endif
-#endif /* LIBC_SCCS and not lint */
#include <assert.h>
#include <errno.h>
@@ -58,6 +61,10 @@ __swsetup(FILE *fp)
{
_DIAGASSERT(fp != NULL);
+ if(fp == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
/* make sure stdio is set up */
if (!__sdidinit)