Subversion Repositories Kolibri OS

Rev

Rev 359 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 359 Rev 550
Line 32... Line 32...
32
 
32
 
33
#include "variety.h"
33
#include "variety.h"
34
#include 
34
#include 
Line 35... Line -...
35
#include 
-
 
36
 
-
 
37
//#if defined(__NT__)
-
 
38
//#elif defined(__OS2__)
-
 
39
//#else
-
 
40
//    #include "tinyio.h"
-
 
41
//#endif
35
#include 
42
 
36
 
43
#include "iomode.h"
37
#include "iomode.h"
44
#include "fileacc.h"
38
#include "fileacc.h"
45
#include "rtcheck.h"
39
#include "rtcheck.h"
46
#include "rtdata.h"
-
 
47
#include "seterrno.h"
40
#include "rtdata.h"
-
 
41
#include "seterrno.h"
-
 
42
#include "qwrite.h"
Line 48... Line 43...
48
//#include "defwin.h"
43
#include "liballoc.h"
49
#include "qwrite.h"
44
 
50
 
45
 
51
/*
46
/*
52
    Use caution when setting the file pointer in a multithreaded
47
    Use caution when setting the file pointer in a multithreaded
53
    application. You must synchronize access to shared resources. For
48
    application. You must synchronize access to shared resources. For
54
    example, an application whose threads share a file handle, update the
49
    example, an application whose threads share a file handle, update the
Line -... Line 50...
-
 
50
    file pointer, and read from the file must protect this sequence by
-
 
51
    using a critical section object or a mutex object.
-
 
52
 */
-
 
53
 
-
 
54
typedef struct
-
 
55
{   DWORD    attr;
-
 
56
    DWORD    flags;
-
 
57
    DWORD    cr_time;
-
 
58
    DWORD    cr_date;
-
 
59
    DWORD    acc_time;
-
 
60
    DWORD    acc_date;
-
 
61
    DWORD    mod_time;
-
 
62
    DWORD    mod_date;
-
 
63
    DWORD    size;
-
 
64
    DWORD    size_high; 
-
 
65
} FILEINFO;
-
 
66
 
-
 
67
typedef struct 
-
 
68
{
-
 
69
  char     *name;
-
 
70
  unsigned int offset;
-
 
71
}__file_handle;
Line 55... Line 72...
55
    file pointer, and read from the file must protect this sequence by
72
 
56
    using a critical section object or a mutex object.
73
int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo);
57
 */
74
int _stdcall write_file(const char *name,const void *buff,unsigned offset,unsigned count,unsigned *writes);
58
 
75
char* getfullpath(const char* path);
59
 
76
 
60
int __qwrite( int handle, const void *buffer, unsigned len )
-
 
61
{
-
 
62
    int             atomic;
77
int __qwrite( int handle, const void *buffer, unsigned len )
63
#if defined(__NT__)
-
 
64
    DWORD           len_written;
-
 
65
    HANDLE          h;
-
 
66
    int             error;
-
 
67
    
-
 
68
#elif defined(__WARP__)
-
 
69
#elif defined(__OS2_286__)
-
 
Line 70... Line 78...
70
#else
78
{
Line 71... Line -...
71
#endif
-
 
72
#if !defined(__NT__)
79
    int             atomic;
73
    tiny_ret_t      rc;
80
    __file_handle   *fh;
74
#endif
81
    unsigned        len_written;
75
 
82
    
76
    __handle_check( handle, -1 );
83
 
-
 
84
    __handle_check( handle, -1 );
-
 
85
 
77
 
86
    fh = (__file_handle*) __getOSHandle( handle );
78
#if defined(__NT__)
87
 
79
    h = __getOSHandle( handle );
-
 
80
#endif
-
 
81
    atomic = 0;
-
 
82
    if( __GetIOMode( handle ) & _APPEND )
-
 
83
    {
88
    atomic = 0;
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
//        }
89
    if( __GetIOMode( handle ) & _APPEND )
93
#elif defined(__OS2__)
-
 
94
#else
-
 
95
        rc = TinySeek( handle, 0L, SEEK_END );
-
 
96
#endif
90
    {
97
#if !defined(__NT__)
-
 
Line 98... Line 91...
98
        if( TINY_ERROR( rc ) ) {
91
      FILEINFO info;
99
            _ReleaseFileH( handle );
92
        
100
            return( __set_errno_dos( TINY_INFO( rc ) ) );
-
 
101
        }
93
      _AccessFileH( handle );
102
#endif
-
 
103
    }
-
 
104
#if defined(__NT__)
-
 
105
 
94
      atomic = 1;
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__)
95
      get_fileinfo(fh->name,&info);
117
#else
96
      fh->offset = info.size;
-
 
97
    };
-
 
98
 
118
    rc = TinyWrite( handle, buffer, len );
99
    if(write_file(fh->name,buffer,fh->offset,len,&len_written))
119
    len_written = TINY_LINFO( rc );
-
 
120
#endif
100
    {
121
 
101
      if ( len_written == 0)
122
#if !defined(__NT__)
-
 
123
    if( TINY_ERROR( rc ) ) {
102
      {
124
        if( atomic == 1 ) {
103
        if( atomic == 1 )
-
 
104
          _ReleaseFileH( handle );
125
            _ReleaseFileH( handle );
105
 
126
        }
106
        return (-1);
127
        return( __set_errno_dos( TINY_INFO( rc ) ) );
107
      };   
128
    }
108
    };
129
#endif
109
    
130
    if( len_written != len ) {
110
    fh->offset+=len_written;
-
 
111
        
-
 
112
 
-
 
113
    if( atomic == 1 )
-
 
114
    {
-
 
115
        _ReleaseFileH( handle );
-
 
116
    }
-
 
117
    return( len_written );
-
 
118
}
-
 
119
 
-
 
120
int write_once(const char *name, void *buffer, unsigned len)
-
 
121
{   char *path;