Subversion Repositories Kolibri OS

Rev

Rev 359 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
550 serge 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 
35
#include 
36
 
37
#include "iomode.h"
38
#include "fileacc.h"
39
#include "rtcheck.h"
40
#include "rtdata.h"
41
#include "seterrno.h"
42
#include "qwrite.h"
43
#include "liballoc.h"
44
 
45
 
46
/*
47
    Use caution when setting the file pointer in a multithreaded
48
    application. You must synchronize access to shared resources. For
49
    example, an application whose threads share a file handle, update the
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;
72
 
73
int _stdcall get_fileinfo(const char *name,FILEINFO* pinfo);
74
int _stdcall write_file(const char *name,const void *buff,unsigned offset,unsigned count,unsigned *writes);
75
char* getfullpath(const char* path);
76
 
77
int __qwrite( int handle, const void *buffer, unsigned len )
78
{
79
    int             atomic;
80
    __file_handle   *fh;
81
    unsigned        len_written;
82
 
83
 
84
    __handle_check( handle, -1 );
85
 
86
    fh = (__file_handle*) __getOSHandle( handle );
87
 
88
    atomic = 0;
89
    if( __GetIOMode( handle ) & _APPEND )
90
    {
91
      FILEINFO info;
92
 
93
      _AccessFileH( handle );
94
      atomic = 1;
95
      get_fileinfo(fh->name,&info);
96
      fh->offset = info.size;
97
    };
98
 
99
    if(write_file(fh->name,buffer,fh->offset,len,&len_written))
100
    {
101
      if ( len_written == 0)
102
      {
103
        if( atomic == 1 )
104
          _ReleaseFileH( handle );
105
 
106
        return (-1);
107
      };
108
    };
109
 
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;
122
    unsigned count;
123
 
124
    path= getfullpath(name);
125
    write_file(path,buffer,0,len,&count);
126
    lib_free(path);
127
    return count;
128
 
129
}