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 fopen_s() - safe version of fopen().
  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 <errno.h>
  42. #include <fcntl.h>
  43. #include <sys/stat.h>
  44. #include "fileacc.h"
  45. #include "fmode.h"
  46. #include "openmode.h"
  47. #include "rtdata.h"
  48. // #include "seterrno.h"
  49. // #include "defwin.h"
  50.  
  51.  
  52. _WCRTLINK errno_t __F_NAME(fopen_s,_wfopen_s)( FILE * __restrict * __restrict streamptr,
  53.                                                const CHAR_TYPE * __restrict filename,
  54.                                                const CHAR_TYPE * __restrict mode)
  55. /**************************************************************************************/
  56. {
  57.     errno_t     rc = -1;
  58.     const char *msg;
  59.  
  60.     /* check for runtime-constraints */
  61.     /* streamptr  not null */
  62.     /* filename   not null */
  63.     /* mode       not null */
  64.     if( __check_constraint_nullptr_msg( msg, streamptr )  &&
  65.         __check_constraint_nullptr_msg( msg, filename ) &&
  66.         __check_constraint_nullptr_msg( msg, mode ) ) {
  67.  
  68.         /* ua.. and uw.. are treated as a.. and w.. */
  69.         if( (*mode == __F_NAME('u',L'u')) &&
  70.             ( (*(mode + 1) == __F_NAME('r',L'r')) ||
  71.               (*(mode + 1) == __F_NAME('w',L'w')) ||
  72.               (*(mode + 1) == __F_NAME('a',L'a'))) ) {
  73.             mode++;                         /* ignore u for now */
  74.         }
  75.         *streamptr = __F_NAME(_fsopen,_wfsopen)( filename, mode, OPENMODE_DENY_COMPAT );
  76.  
  77.         if( *streamptr != NULL ) {  /* if open ok set rc = 0 */
  78.             rc = 0;
  79.         }
  80.     } else {
  81.         /* Runtime-constraints found, store zero in streamptr */
  82.         if( streamptr != NULL ) {
  83.             *streamptr = NULL;
  84.         }
  85.         /* Now call the handler */
  86.         __rtct_fail( __func__, msg, NULL );
  87.     }
  88.     return( rc );
  89. }
  90.