Subversion Repositories Kolibri OS

Rev

Rev 613 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
613 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"
711 serge 44
#include "kolibri.h"
613 serge 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
{
56
  char     *name;
57
  unsigned int offset;
58
}__file_handle;
59
 
60
char* getfullpath(const char* path);
61
 
62
int __qwrite( int handle, const void *buffer, unsigned len )
63
{
64
    int             atomic;
65
    __file_handle   *fh;
66
    unsigned        len_written;
67
 
68
    __handle_check( handle, -1 );
69
 
70
    fh = (__file_handle*) __getOSHandle( handle );
71
 
72
    atomic = 0;
73
    if( __GetIOMode( handle ) & _APPEND )
74
    {
75
      FILEINFO info;
76
 
77
      _AccessFileH( handle );
78
      atomic = 1;
79
      get_fileinfo(fh->name,&info);
80
      fh->offset = info.size;
81
    };
82
 
83
    if(write_file(fh->name,buffer,fh->offset,len,&len_written))
84
    {
85
      if ( len_written == 0)
86
      {
87
        if( atomic == 1 )
88
          _ReleaseFileH( handle );
89
 
90
        return (-1);
91
      };
92
    };
93
 
94
    fh->offset+=len_written;
95
 
96
 
97
    if( atomic == 1 )
98
    {
99
        _ReleaseFileH( handle );
100
    }
101
    return( len_written );
102
}
103
 
104
/********************
105
int write_once(const char *name, void *buffer, unsigned len)
106
{   char *path;
107
    unsigned count;
108
 
109
    path= getfullpath(name);
110
    write_file(path,buffer,0,len,&count);
111
    lib_free(path);
112
    return count;
113
 
114
}
115
 
116
*******************/