1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #define CSV_USE_CSV_ASSERTIONS
21 #include <cosv/csv_env.hxx>
23 #include <cosv/comfunc.hxx>
24 #include <cosv/string.hxx>
25 #include <cosv/streamstr.hxx>
26 #include <cosv/std_outp.hxx>
27 #include <cosv/tpl/dyn.hxx>
28 #include <cosv/file.hxx>
30 // NOT FULLY DECLARED SERVICES
37 File::File( const char * i_sLocation
,
46 File::File( const String
& i_sLocation
,
62 File::do_read( void * out_pDest
,
65 if ( NOT
inq_is_open() )
68 if ( eLastIO
== io_write
)
69 ::fseek( pStream
, 0, SEEK_CUR
);
70 uintt ret
= position();
71 int iRet
= ::fread( out_pDest
, 1, i_nNrofBytes
, pStream
);
73 fprintf(stderr
, "warning: read failed in %s line %d \n", __FILE__
, __LINE__
);
75 ret
= position() - ret
;
84 if ( NOT
inq_is_open() )
86 return feof(pStream
) != 0;
90 File::do_write( const void * i_pSrc
,
93 if ( NOT
inq_is_open() )
96 if ( eLastIO
== io_write
)
97 ::fseek( pStream
, 0, SEEK_CUR
);
99 uintt ret
= ::fwrite( i_pSrc
, 1, i_nNrofBytes
, pStream
);
106 File::do_seek( intt i_nDistance
,
107 seek_dir i_eStartPoint
)
109 if ( NOT
inq_is_open() )
112 static int eSearchDir
[3] = { SEEK_SET
, SEEK_CUR
, SEEK_END
};
116 eSearchDir
[i_eStartPoint
] );
121 File::inq_position() const
124 return uintt( ::ftell(pStream
) );
130 File::do_open( uintt i_nOpenMode
)
134 if ( i_nOpenMode
== 0 OR i_nOpenMode
== nMode
)
139 if ( i_nOpenMode
!= 0 )
142 const char * sFacadeMode
= "";
145 case CFM_RW
: sFacadeMode
= "r+b";
147 case CFM_CREATE
: sFacadeMode
= "w+b";
149 case CFM_READ
: sFacadeMode
= "rb";
155 pStream
= ::fopen( StrPath(), sFacadeMode
);
156 if ( pStream
== 0 AND nMode
== CFM_RW
)
159 pStream
= ::fopen( StrPath(), sFacadeMode
);
177 File::inq_is_open() const
183 File::inq_MyPath() const
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */