| ︙ | | | ︙ | |
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/*
** Return TRUE if the named file is an executable. Return false
** for directories, devices, fifos, symlinks, etc.
*/
int file_isexe(const char *zFilename){
if( getStat(zFilename) || !S_ISREG(fileStat.st_mode) ) return 0;
#ifdef __MINGW32__
return ((S_IXUSR)&fileStat.st_mode)!=0;
#else
return ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0;
#endif
}
|
|
>
>
>
|
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*
** Return TRUE if the named file is an executable. Return false
** for directories, devices, fifos, symlinks, etc.
*/
int file_isexe(const char *zFilename){
if( getStat(zFilename) || !S_ISREG(fileStat.st_mode) ) return 0;
#if defined(_WIN32)
# if defined(__DMC__)
# define S_IXUSR _S_IEXEC
# endif
return ((S_IXUSR)&fileStat.st_mode)!=0;
#else
return ((S_IXUSR|S_IXGRP|S_IXOTH)&fileStat.st_mode)!=0;
#endif
}
|
| ︙ | | | ︙ | |
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
fclose(out);
}
/*
** Set or clear the execute bit on a file.
*/
void file_setexe(const char *zFilename, int onoff){
#ifndef __MINGW32__
struct stat buf;
if( stat(zFilename, &buf)!=0 ) return;
if( onoff ){
if( (buf.st_mode & 0111)!=0111 ){
chmod(zFilename, buf.st_mode | 0111);
}
}else{
if( (buf.st_mode & 0111)!=0 ){
chmod(zFilename, buf.st_mode & ~0111);
}
}
#endif /* __MINGW32__ */
}
/*
** Create the directory named in the argument, if it does not already
** exist. If forceFlag is 1, delete any prior non-directory object
** with the same name.
**
** Return the number of errors.
*/
int file_mkdir(const char *zName, int forceFlag){
int rc = file_isdir(zName);
if( rc==2 ){
if( !forceFlag ) return 1;
unlink(zName);
}
if( rc!=1 ){
#ifdef __MINGW32__
return mkdir(zName);
#else
return mkdir(zName, 0755);
#endif
}
return 0;
}
|
|
|
|
|
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
fclose(out);
}
/*
** Set or clear the execute bit on a file.
*/
void file_setexe(const char *zFilename, int onoff){
#if !defined(_WIN32)
struct stat buf;
if( stat(zFilename, &buf)!=0 ) return;
if( onoff ){
if( (buf.st_mode & 0111)!=0111 ){
chmod(zFilename, buf.st_mode | 0111);
}
}else{
if( (buf.st_mode & 0111)!=0 ){
chmod(zFilename, buf.st_mode & ~0111);
}
}
#endif /* _WIN32 */
}
/*
** Create the directory named in the argument, if it does not already
** exist. If forceFlag is 1, delete any prior non-directory object
** with the same name.
**
** Return the number of errors.
*/
int file_mkdir(const char *zName, int forceFlag){
int rc = file_isdir(zName);
if( rc==2 ){
if( !forceFlag ) return 1;
unlink(zName);
}
if( rc!=1 ){
#if defined(_WIN32)
return mkdir(zName);
#else
return mkdir(zName, 0755);
#endif
}
return 0;
}
|
| ︙ | | | ︙ | |
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
** * removing /A/../
**
** Changes are made in-place. Return the new name length.
*/
int file_simplify_name(char *z, int n){
int i, j;
if( n<0 ) n = strlen(z);
#ifdef __MINGW32__
for(i=0; i<n; i++){
if( z[i]=='\\' ) z[i] = '/';
}
#endif
while( n>1 && z[n-1]=='/' ){ n--; }
for(i=j=0; i<n; i++){
if( z[i]=='/' ){
|
|
|
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
** * removing /A/../
**
** Changes are made in-place. Return the new name length.
*/
int file_simplify_name(char *z, int n){
int i, j;
if( n<0 ) n = strlen(z);
#if defined(_WIN32)
for(i=0; i<n; i++){
if( z[i]=='\\' ) z[i] = '/';
}
#endif
while( n>1 && z[n-1]=='/' ){ n--; }
for(i=j=0; i<n; i++){
if( z[i]=='/' ){
|
| ︙ | | | ︙ | |
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
** Make the name absolute if it is relative.
** Remove redundant / characters
** Remove all /./ path elements.
** Convert /A/../ to just /
*/
void file_canonical_name(const char *zOrigName, Blob *pOut){
if( zOrigName[0]=='/'
#ifdef __MINGW32__
|| zOrigName[0]=='\\'
|| (strlen(zOrigName)>3 && zOrigName[1]==':'
&& (zOrigName[2]=='\\' || zOrigName[2]=='/'))
#endif
){
blob_set(pOut, zOrigName);
blob_materialize(pOut);
|
|
|
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
** Make the name absolute if it is relative.
** Remove redundant / characters
** Remove all /./ path elements.
** Convert /A/../ to just /
*/
void file_canonical_name(const char *zOrigName, Blob *pOut){
if( zOrigName[0]=='/'
#if defined(_WIN32)
|| zOrigName[0]=='\\'
|| (strlen(zOrigName)>3 && zOrigName[1]==':'
&& (zOrigName[2]=='\\' || zOrigName[2]=='/'))
#endif
){
blob_set(pOut, zOrigName);
blob_materialize(pOut);
|
| ︙ | | | ︙ | |
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
**
** Canonical names are full pathnames using "/" not "\" and which
** contain no "/./" or "/../" terms.
*/
int file_is_canonical(const char *z){
int i;
if( z[0]!='/'
#ifdef __MINGW32__
&& (z[0]==0 || z[1]!=':' || z[2]!='/')
#endif
) return 0;
for(i=0; z[i]; i++){
if( z[i]=='\\' ) return 0;
if( z[i]=='/' ){
|
|
|
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
**
** Canonical names are full pathnames using "/" not "\" and which
** contain no "/./" or "/../" terms.
*/
int file_is_canonical(const char *z){
int i;
if( z[0]!='/'
#if defined(_WIN32)
&& (z[0]==0 || z[1]!=':' || z[2]!='/')
#endif
) return 0;
for(i=0; z[i]; i++){
if( z[i]=='\\' ) return 0;
if( z[i]=='/' ){
|
| ︙ | | | ︙ | |