1 /*---------------------------------------------------------------------------*
2 * PFileWrapUNIX_OS_Specific.c *
3 * *
4 * Copyright 2007, 2008 Nuance Communciations, Inc. *
5 * *
6 * Licensed under the Apache License, Version 2.0 (the 'License'); *
7 * you may not use this file except in compliance with the License. *
8 * *
9 * You may obtain a copy of the License at *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, software *
13 * distributed under the License is distributed on an 'AS IS' BASIS, *
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 * See the License for the specific language governing permissions and *
16 * limitations under the License. *
17 * *
18 *---------------------------------------------------------------------------*/
19
20 #include <sys/types.h>
21 #include <sys/stat.h>
22
23 #include "errno.h"
24 #include "PFileSystemImpl.h"
25 #include "PANSIFileSystem.h"
26 #include "PANSIFileSystemImpl.h"
27 #include "phashtable.h"
28 #include "LCHAR.h"
29 #include "plog.h"
30
pf_make_dir(const LCHAR * path)31 ESR_ReturnCode pf_make_dir ( const LCHAR* path )
32 {
33 ESR_ReturnCode rc;
34
35 passert(path!=NULL);
36
37 if ( mkdir ( path, S_IRWXU|S_IRWXG|S_IRWXO ) == 0)
38 {
39 rc = ESR_SUCCESS;
40 }
41 else
42 {
43 switch (errno)
44 {
45 case EEXIST:
46 rc = ESR_IDENTIFIER_COLLISION;
47 break;
48
49 case ENOENT:
50 rc = ESR_NO_MATCH_ERROR;
51 break;
52
53 default:
54 PLogError ( L("ESR_INVALID_STATE") );
55 rc = ESR_INVALID_STATE;
56 break;
57 }
58 }
59 return ( rc );
60 }
61
62
63
pf_get_cwd(LCHAR * path,size_t * len)64 ESR_ReturnCode pf_get_cwd ( LCHAR* path, size_t *len )
65 {
66 ESR_ReturnCode rc;
67
68 if ( path != NULL )
69 {
70 if ( getcwd ( path, *len ) != NULL)
71 {
72 rc = ESR_SUCCESS;
73 }
74 else
75 {
76 switch ( errno )
77 {
78 case ERANGE:
79 rc = ESR_BUFFER_OVERFLOW;
80 break;
81
82 case ENOMEM:
83 rc = ESR_OUT_OF_MEMORY;
84 break;
85
86 default:
87 PLogError(L("ESR_INVALID_STATE"));
88 rc = ESR_INVALID_STATE;
89 break;
90 }
91 }
92 }
93 else
94 {
95 rc = ESR_INVALID_ARGUMENT;
96 PLogError(ESR_rc2str(rc));
97 }
98
99 return ( rc );
100 }
101
102
103
pf_change_dir(const LCHAR * path)104 ESR_ReturnCode pf_change_dir ( const LCHAR* path )
105 {
106 ESR_ReturnCode rc;
107
108 passert ( path != NULL );
109 passert ( *path != '\0' );
110
111 if ( chdir ( path ) == 0 )
112 rc = ESR_SUCCESS;
113 else
114 rc = ESR_NO_MATCH_ERROR;
115 return ( rc );
116 }
117