1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <precomp.h>
25 #include <cosv/persist.hxx>
26 
27 // NOT FULLY DECLARED SERVICES
28 #include <cosv/streamstr.hxx>
29 #include <cosv/ploc.hxx>
30 
31 
32 #ifdef WNT
33 #include <io.h>
34 
35 namespace csv
36 {
37 namespace ploc
38 {
39 
40 bool
Exists() const41 Persistent::Exists() const
42 {
43     return access( StrPath(), 00) == 0;
44 }
45 
46 } // namespace ploc
47 } // namespace csv
48 
49 
50 #elif defined(UNX)
51 #include <unistd.h>
52 
53 /*
54 #ifndef __SUNPRO_CC
55 #include <unistd.h>
56 #else
57 #define	F_OK	0	// Test for existence of File
58 extern int access(const char *, int);
59 #endif
60 */
61 
62 namespace csv
63 {
64 namespace ploc
65 {
66 
67 bool
Exists() const68 Persistent::Exists() const
69 {
70     return access( StrPath(), F_OK ) == 0;
71 }
72 
73 
74 } // namespace ploc
75 } // namespace csv
76 
77 #else
78 #error  For using csv::ploc there has to be defined: WNT or UNX.
79 #endif
80 
81 namespace csv
82 {
83 namespace ploc
84 {
85 
86 const char *
StrPath() const87 Persistent::StrPath() const
88 {
89     if (sPath.empty() )
90     {
91 #ifndef CSV_NO_MUTABLE
92         StreamStr & rsPath = sPath;
93 #else
94         StreamStr & rsPath = const_cast< StreamStr& >(sPath);
95 #endif
96         rsPath.seekp(0);
97         rsPath << MyPath();
98         if (MyPath().IsDirectory())
99             rsPath.pop_back(1);    // Remove closing delimiter.
100     }
101     return sPath.c_str();
102 }
103 
104 } // namespace ploc
105 } // namespace csv
106 
107 
108 
109 
110