1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: file.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <cosv/file.hxx>
34 // NOT FULLY DECLARED SERVICES
41 File::File( uintt i_nMode
)
49 File::File( const ploc::Path
& i_rLocation
,
58 File::File( const char * i_sLocation
,
67 File::File( const String
& i_sLocation
,
83 File::Assign( ploc::Path i_rLocation
)
94 File::Assign( const char * i_sLocation
)
100 aPath
.Set( i_sLocation
);
105 File::Assign( const String
& i_sLocation
)
111 aPath
.Set( i_sLocation
);
116 File::do_read( void * out_pDest
,
119 if ( NOT
inq_is_open() )
122 if ( eLastIO
== io_write
)
123 ::fseek( pStream
, 0, SEEK_CUR
);
124 uintt ret
= position();
125 int iRet
= ::fread( out_pDest
, 1, i_nNrofBytes
, pStream
);
127 fprintf(stderr
, "warning: read failed in %s line %d \n", __FILE__
, __LINE__
);
129 ret
= position() - ret
;
136 File::inq_eod() const
138 if ( NOT
inq_is_open() )
140 return feof(pStream
) != 0;
144 File::do_write( const void * i_pSrc
,
147 if ( NOT
inq_is_open() )
150 if ( eLastIO
== io_write
)
151 ::fseek( pStream
, 0, SEEK_CUR
);
152 uintt ret
= position();
153 ::fwrite( i_pSrc
, 1, i_nNrofBytes
, pStream
);
154 ret
= position() - ret
;
161 File::do_seek( intt i_nDistance
,
162 seek_dir i_eStartPoint
)
164 if ( NOT
inq_is_open() )
167 static int eSearchDir
[3] = { SEEK_SET
, SEEK_CUR
, SEEK_END
};
171 eSearchDir
[i_eStartPoint
] );
176 File::inq_position() const
179 return uintt( ::ftell(pStream
) );
185 File::do_open( uintt i_nOpenMode
)
189 if ( i_nOpenMode
== 0 OR i_nOpenMode
== nMode
)
194 if ( i_nOpenMode
!= 0 )
197 const char * sFacadeMode
= "";
200 case CFM_RW
: sFacadeMode
= "r+b";
202 case CFM_CREATE
: sFacadeMode
= "w+b";
204 case CFM_READ
: sFacadeMode
= "rb";
210 pStream
= ::fopen( StrPath(), sFacadeMode
);
211 if ( pStream
== 0 AND nMode
== CFM_RW
)
214 pStream
= ::fopen( StrPath(), sFacadeMode
);
232 File::inq_is_open() const
238 File::inq_MyPath() const