1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 #include <cosv/file.hxx>
31 // NOT FULLY DECLARED SERVICES
38 File::File( uintt i_nMode
)
46 File::File( const ploc::Path
& i_rLocation
,
55 File::File( const char * i_sLocation
,
64 File::File( const String
& i_sLocation
,
80 File::Assign( ploc::Path i_rLocation
)
91 File::Assign( const char * i_sLocation
)
97 aPath
.Set( i_sLocation
);
102 File::Assign( const String
& i_sLocation
)
108 aPath
.Set( i_sLocation
);
113 File::do_read( void * out_pDest
,
116 if ( NOT
inq_is_open() )
119 if ( eLastIO
== io_write
)
120 ::fseek( pStream
, 0, SEEK_CUR
);
121 uintt ret
= position();
122 int iRet
= ::fread( out_pDest
, 1, i_nNrofBytes
, pStream
);
124 fprintf(stderr
, "warning: read failed in %s line %d \n", __FILE__
, __LINE__
);
126 ret
= position() - ret
;
133 File::inq_eod() const
135 if ( NOT
inq_is_open() )
137 return feof(pStream
) != 0;
141 File::do_write( const void * i_pSrc
,
144 if ( NOT
inq_is_open() )
147 if ( eLastIO
== io_write
)
148 ::fseek( pStream
, 0, SEEK_CUR
);
149 uintt ret
= position();
150 ::fwrite( i_pSrc
, 1, i_nNrofBytes
, pStream
);
151 ret
= position() - ret
;
158 File::do_seek( intt i_nDistance
,
159 seek_dir i_eStartPoint
)
161 if ( NOT
inq_is_open() )
164 static int eSearchDir
[3] = { SEEK_SET
, SEEK_CUR
, SEEK_END
};
168 eSearchDir
[i_eStartPoint
] );
173 File::inq_position() const
176 return uintt( ::ftell(pStream
) );
182 File::do_open( uintt i_nOpenMode
)
186 if ( i_nOpenMode
== 0 OR i_nOpenMode
== nMode
)
191 if ( i_nOpenMode
!= 0 )
194 const char * sFacadeMode
= "";
197 case CFM_RW
: sFacadeMode
= "r+b";
199 case CFM_CREATE
: sFacadeMode
= "w+b";
201 case CFM_READ
: sFacadeMode
= "rb";
207 pStream
= ::fopen( StrPath(), sFacadeMode
);
208 if ( pStream
== 0 AND nMode
== CFM_RW
)
211 pStream
= ::fopen( StrPath(), sFacadeMode
);
229 File::inq_is_open() const
235 File::inq_MyPath() const