Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  Implementation of freopen_s() - safe version of freopen().
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include "saferlib.h"
  34. #include "widechar.h"
  35. #include <wchar.h>
  36. #include <stdio.h>
  37. #include <ctype.h>
  38. #ifdef __WIDECHAR__
  39.     #include <wctype.h>
  40. #endif
  41. #include <fcntl.h>
  42. #include <sys/stat.h>
  43. #include "fileacc.h"
  44. #include "fmode.h"
  45. #include "openmode.h"
  46. #include "rtdata.h"
  47.  
  48.  
  49. _WCRTLINK errno_t __F_NAME(freopen_s,_wfreopen_s)(
  50.                           FILE * __restrict * __restrict newstreamptr,
  51.                           const CHAR_TYPE * __restrict filename,
  52.                           const CHAR_TYPE * __restrict mode,
  53.                           FILE * __restrict stream )
  54. /********************************************************************/
  55. {
  56.     errno_t     rc = -1;
  57.     const char *msg;
  58.  
  59.     /* check for runtime-constraints */
  60.     /* newstreamptr  not null */
  61.     /* mode          not null */
  62.     /* stream        not null */
  63.     if( __check_constraint_nullptr_msg( msg, newstreamptr )  &&
  64.         __check_constraint_nullptr_msg( msg, mode ) &&
  65.         __check_constraint_nullptr_msg( msg, stream ) ) {
  66.  
  67.         /* ua.. and uw.. are treated as a.. and w.. */
  68.         if( (*mode == __F_NAME('u',L'u')) &&
  69.             ( (*(mode + 1) == __F_NAME('r',L'r')) ||
  70.               (*(mode + 1) == __F_NAME('w',L'w')) ||
  71.               (*(mode + 1) == __F_NAME('a',L'a'))) ) {
  72.             mode++;                         /* ignore u for now */
  73.         }
  74.         *newstreamptr = __F_NAME(freopen,_wfreopen)( filename, mode, stream );
  75.  
  76.         if( *newstreamptr != NULL ) {  /* if reopen ok set rc = 0 */
  77.             rc = 0;
  78.         }
  79.     } else {
  80.         /* Runtime-constraints found, store zero in newstreamptr */
  81.         if( newstreamptr != NULL ) {
  82.             *newstreamptr = NULL;
  83.         }
  84.         /* Now call the handler */
  85.         __rtct_fail( __func__, msg, NULL );
  86.     }
  87.     return( rc );
  88. }
  89.