Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/stdio/freopen.c')
-rw-r--r--newlib/libc/stdio/freopen.c125
1 files changed, 18 insertions, 107 deletions
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index f1fc9dad8..63f583375 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1990, 2006 The Regents of the University of California.
+ * Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
@@ -21,15 +21,11 @@ FUNCTION
INDEX
freopen
-INDEX
- _freopen_r
ANSI_SYNOPSIS
#include <stdio.h>
FILE *freopen(const char *<[file]>, const char *<[mode]>,
FILE *<[fp]>);
- FILE *_freopen_r(struct _reent *<[ptr]>, const char *<[file]>,
- const char *<[mode]>, FILE *<[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
@@ -38,12 +34,6 @@ TRAD_SYNOPSIS
char *<[mode]>;
FILE *<[fp]>;
- FILE *_freopen_r(<[ptr]>, <[file]>, <[mode]>, <[fp]>)
- struct _reent *<[ptr]>;
- char *<[file]>;
- char *<[mode]>;
- FILE *<[fp]>;
-
DESCRIPTION
Use this variant of <<fopen>> if you wish to specify a particular file
descriptor <[fp]> (notably <<stdin>>, <<stdout>>, or <<stderr>>) for
@@ -55,12 +45,6 @@ it).
<[file]> and <[mode]> are used just as in <<fopen>>.
-If <[file]> is <<NULL>>, the underlying stream is modified rather than
-closed. The file cannot be given a more permissive access mode (for
-example, a <[mode]> of "w" will fail on a read-only file descriptor),
-but can change status such as append or binary mode. If modification
-is not possible, failure occurs.
-
RETURNS
If successful, the result is the same as the argument <[fp]>. If the
file cannot be opened as specified, the result is <<NULL>>.
@@ -72,14 +56,10 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
<<lseek>>, <<open>>, <<read>>, <<sbrk>>, <<write>>.
*/
-#include <_ansi.h>
-#include <reent.h>
#include <time.h>
#include <stdio.h>
-#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
-#include <sys/lock.h>
#include "local.h"
/*
@@ -87,27 +67,21 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
*/
FILE *
-_DEFUN(_freopen_r, (ptr, file, mode, fp),
- struct _reent *ptr _AND
- _CONST char *file _AND
- _CONST char *mode _AND
- register FILE *fp)
+_DEFUN (freopen, (file, mode, fp),
+ _CONST char *file _AND
+ _CONST char *mode _AND
+ register FILE *fp)
{
register int f;
- int flags, oflags;
- int e = 0;
-
- __sfp_lock_acquire ();
+ int flags, oflags, e;
+ struct _reent *ptr;
- CHECK_INIT (ptr);
-
- _flockfile (fp);
+ CHECK_INIT (fp);
+ ptr = fp->_data;
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
- _funlockfile (fp);
- _CAST_VOID _fclose_r (ptr, fp);
- __sfp_lock_release ();
+ (void) fclose (fp);
return NULL;
}
@@ -124,61 +98,18 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
else
{
if (fp->_flags & __SWR)
- _CAST_VOID fflush (fp);
- /*
- * If close is NULL, closing is a no-op, hence pointless.
- * If file is NULL, the file should not be closed.
- */
- if (fp->_close != NULL && file != NULL)
- _CAST_VOID (*fp->_close) (fp->_cookie);
+ (void) fflush (fp);
+ /* if close is NULL, closing is a no-op, hence pointless */
+ if (fp->_close != NULL)
+ (void) (*fp->_close) (fp->_cookie);
}
/*
- * Now get a new descriptor to refer to the new file, or reuse the
- * existing file descriptor if file is NULL.
+ * Now get a new descriptor to refer to the new file.
*/
- if (file != NULL)
- {
- f = _open_r (ptr, (char *) file, oflags, 0666);
- e = ptr->_errno;
- }
- else
- {
-#ifdef HAVE_FCNTL
- int oldflags;
- /*
- * Reuse the file descriptor, but only if the new access mode is
- * equal or less permissive than the old. F_SETFL correctly
- * ignores creation flags.
- */
- f = fp->_file;
- if ((oldflags = _fcntl_r (ptr, f, F_GETFL, 0)) == -1
- || ! ((oldflags & O_ACCMODE) == O_RDWR
- || ((oldflags ^ oflags) & O_ACCMODE) == 0)
- || _fcntl_r (ptr, f, F_SETFL, oflags) == -1)
- f = -1;
-#else
- /* We cannot modify without fcntl support. */
- f = -1;
-#endif
-
-#ifdef __SCLE
- /*
- * F_SETFL doesn't change textmode. Don't mess with modes of ttys.
- */
- if (0 <= f && ! isatty (f)
- && setmode (f, oflags & (O_BINARY | O_TEXT)) == -1)
- f = -1;
-#endif
-
- if (f < 0)
- {
- e = EBADF;
- if (fp->_close != NULL)
- _CAST_VOID (*fp->_close) (fp->_cookie);
- }
- }
+ f = _open_r (ptr, (char *) file, oflags, 0666);
+ e = ptr->_errno;
/*
* Finish closing fp. Even if the open succeeded above,
@@ -206,11 +137,6 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
{ /* did not get it after all */
fp->_flags = 0; /* set it free */
ptr->_errno = e; /* restore in case _close clobbered */
- _funlockfile (fp);
-#ifndef __SINGLE_THREAD__
- __lock_close_recursive (fp->_lock);
-#endif
- __sfp_lock_release ();
return NULL;
}
@@ -223,24 +149,9 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
fp->_close = __sclose;
#ifdef __SCLE
- if (__stextmode (fp->_file))
+ if (__stextmode(fp->_file))
fp->_flags |= __SCLE;
#endif
- _funlockfile (fp);
- __sfp_lock_release ();
return fp;
}
-
-#ifndef _REENT_ONLY
-
-FILE *
-_DEFUN(freopen, (file, mode, fp),
- _CONST char *file _AND
- _CONST char *mode _AND
- register FILE *fp)
-{
- return _freopen_r (_REENT, file, mode, fp);
-}
-
-#endif /*!_REENT_ONLY */