Subversion Repositories Kolibri OS

Rev

Go to most recent revision | 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:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
  28. *               DESCRIBE IT HERE!
  29. *
  30. ****************************************************************************/
  31.  
  32.  
  33. #include "variety.h"
  34. #include <stdio.h>
  35. #include <errno.h>
  36.  
  37. //#if defined(__NT__)
  38. //#elif defined(__OS2__)
  39. //#else
  40. //    #include "tinyio.h"
  41. //#endif
  42.  
  43. #include "iomode.h"
  44. #include "fileacc.h"
  45. #include "rtcheck.h"
  46. #include "rtdata.h"
  47. #include "seterrno.h"
  48. //#include "defwin.h"
  49. #include "qwrite.h"
  50.  
  51. /*
  52.     Use caution when setting the file pointer in a multithreaded
  53.     application. You must synchronize access to shared resources. For
  54.     example, an application whose threads share a file handle, update the
  55.     file pointer, and read from the file must protect this sequence by
  56.     using a critical section object or a mutex object.
  57.  */
  58.  
  59.  
  60. int __qwrite( int handle, const void *buffer, unsigned len )
  61. {
  62.     int             atomic;
  63. #if defined(__NT__)
  64.     DWORD           len_written;
  65.     HANDLE          h;
  66.     int             error;
  67.    
  68. #elif defined(__WARP__)
  69. #elif defined(__OS2_286__)
  70. #else
  71. #endif
  72. #if !defined(__NT__)
  73.     tiny_ret_t      rc;
  74. #endif
  75.  
  76.     __handle_check( handle, -1 );
  77.  
  78. #if defined(__NT__)
  79.     h = __getOSHandle( handle );
  80. #endif
  81.     atomic = 0;
  82.     if( __GetIOMode( handle ) & _APPEND )
  83.     {
  84.         _AccessFileH( handle );
  85.         atomic = 1;
  86. #if defined(__NT__)
  87. //        if( SetFilePointer( h, 0, NULL, FILE_END ) == -1 )
  88. //        {
  89. //            error = GetLastError();
  90. //            _ReleaseFileH( handle );
  91. //            return( __set_errno_dos( error ) );
  92. //        }
  93. #elif defined(__OS2__)
  94. #else
  95.         rc = TinySeek( handle, 0L, SEEK_END );
  96. #endif
  97. #if !defined(__NT__)
  98.         if( TINY_ERROR( rc ) ) {
  99.             _ReleaseFileH( handle );
  100.             return( __set_errno_dos( TINY_INFO( rc ) ) );
  101.         }
  102. #endif
  103.     }
  104. #if defined(__NT__)
  105.  
  106. //    if( !WriteFile( h, buffer, len, &len_written, NULL ) )
  107. //    {
  108. //        error = GetLastError();
  109. //        if( atomic == 1 ) {
  110. //            _ReleaseFileH( handle );
  111. //        }
  112. //        return( __set_errno_dos( error ) );
  113. //    }
  114.    
  115. #elif defined(__OS2__)
  116. #elif defined(__WINDOWS_386__)
  117. #else
  118.     rc = TinyWrite( handle, buffer, len );
  119.     len_written = TINY_LINFO( rc );
  120. #endif
  121.  
  122. #if !defined(__NT__)
  123.     if( TINY_ERROR( rc ) ) {
  124.         if( atomic == 1 ) {
  125.             _ReleaseFileH( handle );
  126.         }
  127.         return( __set_errno_dos( TINY_INFO( rc ) ) );
  128.     }
  129. #endif
  130.     if( len_written != len ) {
  131.         __set_errno( ENOSPC );
  132.     }
  133.     if( atomic == 1 )
  134.     {
  135.         _ReleaseFileH( handle );
  136.     }
  137.     return( len_written );
  138. }
  139.