1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/*
* tclUnixFile.c --
*
* This file contains wrappers around UNIX file handling functions.
* These wrappers mask differences between Windows and UNIX.
*
* Copyright (c) 1995-1998 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclUnixFile.c,v 1.12 2001/08/30 08:53:15 vincentdarley Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
/*
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/*
* tclUnixFile.c --
*
* This file contains wrappers around UNIX file handling functions.
* These wrappers mask differences between Windows and UNIX.
*
* Copyright (c) 1995-1998 Sun Microsystems, Inc.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclUnixFile.c,v 1.12.6.1 2001/09/25 10:24:07 dkf Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
/*
|
| ︙ | | | ︙ | |
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
char *
TclpFindExecutable(argv0)
CONST char *argv0; /* The value of the application's argv[0]
* (native). */
{
CONST char *name, *p;
struct stat statBuf;
int length;
Tcl_DString buffer, nameString;
if (argv0 == NULL) {
return NULL;
}
if (tclNativeExecutableName != NULL) {
|
|
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
char *
TclpFindExecutable(argv0)
CONST char *argv0; /* The value of the application's argv[0]
* (native). */
{
CONST char *name, *p;
Tcl_StatBuf statBuf;
int length;
Tcl_DString buffer, nameString;
if (argv0 == NULL) {
return NULL;
}
if (tclNativeExecutableName != NULL) {
|
| ︙ | | | ︙ | |
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
if (p[-1] != '/') {
Tcl_DStringAppend(&buffer, "/", 1);
}
}
name = Tcl_DStringAppend(&buffer, argv0, -1);
/*
* INTL: The following calls to access() and stat() should not be
* converted to Tclp routines because they need to operate on native
* strings directly.
*/
if ((access(name, X_OK) == 0) /* INTL: Native. */
&& (stat(name, &statBuf) == 0) /* INTL: Native. */
&& S_ISREG(statBuf.st_mode)) {
goto gotName;
}
if (*p == '\0') {
break;
} else if (*(p+1) == 0) {
p = "./";
|
|
|
|
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
if (p[-1] != '/') {
Tcl_DStringAppend(&buffer, "/", 1);
}
}
name = Tcl_DStringAppend(&buffer, argv0, -1);
/*
* INTL: The following calls to access() and stat64() should not be
* converted to Tclp routines because they need to operate on native
* strings directly.
*/
if ((access(name, X_OK) == 0) /* INTL: Native. */
&& (stat64(name, &statBuf) == 0) /* INTL: Native. */
&& S_ISREG(statBuf.st_mode)) {
goto gotName;
}
if (*p == '\0') {
break;
} else if (*(p+1) == 0) {
p = "./";
|
| ︙ | | | ︙ | |
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
Tcl_GlobTypeData *types; /* Object containing list of acceptable types.
* May be NULL. In particular the directory
* flag is very important. */
{
char *native, *fname, *dirName;
DIR *d;
Tcl_DString ds;
struct stat statBuf;
int matchHidden;
int nativeDirLen;
int result = TCL_OK;
Tcl_DString dsOrig;
Tcl_Obj *fileNamePtr;
int baseLength;
|
|
|
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
Tcl_GlobTypeData *types; /* Object containing list of acceptable types.
* May be NULL. In particular the directory
* flag is very important. */
{
char *native, *fname, *dirName;
DIR *d;
Tcl_DString ds;
Tcl_StatBuf statBuf;
int matchHidden;
int nativeDirLen;
int result = TCL_OK;
Tcl_DString dsOrig;
Tcl_Obj *fileNamePtr;
int baseLength;
|
| ︙ | | | ︙ | |
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
/*
* Now open the directory for reading and iterate over the contents.
*/
native = Tcl_UtfToExternalDString(NULL, dirName, -1, &ds);
if ((stat(native, &statBuf) != 0) /* INTL: UTF-8. */
|| !S_ISDIR(statBuf.st_mode)) {
Tcl_DStringFree(&dsOrig);
Tcl_DStringFree(&ds);
return TCL_OK;
}
d = opendir(native); /* INTL: Native. */
|
|
|
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
/*
* Now open the directory for reading and iterate over the contents.
*/
native = Tcl_UtfToExternalDString(NULL, dirName, -1, &ds);
if ((stat64(native, &statBuf) != 0) /* INTL: UTF-8. */
|| !S_ISDIR(statBuf.st_mode)) {
Tcl_DStringFree(&dsOrig);
Tcl_DStringFree(&ds);
return TCL_OK;
}
d = opendir(native); /* INTL: Native. */
|
| ︙ | | | ︙ | |
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
if (Tcl_StringMatch(utf, pattern) != 0) {
int typeOk = 1;
Tcl_DStringSetLength(&dsOrig, baseLength);
Tcl_DStringAppend(&dsOrig, utf, -1);
fname = Tcl_DStringValue(&dsOrig);
if (types != NULL) {
struct stat buf;
char *nativeEntry;
Tcl_DStringSetLength(&ds, nativeDirLen);
Tcl_DStringAppend(&ds, entryPtr->d_name, -1);
nativeEntry = Tcl_DStringValue(&ds);
/*
* The native name of the file is in entryPtr->d_name.
* We can use this below.
*/
if (types->perm != 0) {
if (stat(nativeEntry, &buf) != 0) {
/*
* Either the file has disappeared between the
* 'readdir' call and the 'stat' call, or
* the file is a link to a file which doesn't
* exist (which we could ascertain with
* lstat), or there is some other strange
* problem. In all these cases, we define this
* to mean the file does not match any defined
* permission, and therefore it is not
* added to the list of files to return.
*/
typeOk = 0;
}
|
|
|
|
|
|
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
if (Tcl_StringMatch(utf, pattern) != 0) {
int typeOk = 1;
Tcl_DStringSetLength(&dsOrig, baseLength);
Tcl_DStringAppend(&dsOrig, utf, -1);
fname = Tcl_DStringValue(&dsOrig);
if (types != NULL) {
Tcl_StatBuf buf;
char *nativeEntry;
Tcl_DStringSetLength(&ds, nativeDirLen);
Tcl_DStringAppend(&ds, entryPtr->d_name, -1);
nativeEntry = Tcl_DStringValue(&ds);
/*
* The native name of the file is in entryPtr->d_name.
* We can use this below.
*/
if (types->perm != 0) {
if (stat64(nativeEntry, &buf) != 0) {
/*
* Either the file has disappeared between the
* 'readdir' call and the 'stat64' call, or
* the file is a link to a file which doesn't
* exist (which we could ascertain with
* lstat64), or there is some other strange
* problem. In all these cases, we define this
* to mean the file does not match any defined
* permission, and therefore it is not
* added to the list of files to return.
*/
typeOk = 0;
}
|
| ︙ | | | ︙ | |
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
(access(entryPtr->d_name, X_OK) != 0))
)) {
typeOk = 0;
}
}
if (typeOk && (types->type != 0)) {
if (types->perm == 0) {
/* We haven't yet done a stat on the file */
if (stat(nativeEntry, &buf) != 0) {
/* Posix error occurred */
typeOk = 0;
}
}
if (typeOk) {
/*
* In order bcdpfls as in 'find -t'
|
|
|
|
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
(access(entryPtr->d_name, X_OK) != 0))
)) {
typeOk = 0;
}
}
if (typeOk && (types->type != 0)) {
if (types->perm == 0) {
/* We haven't yet done a stat64 on the file */
if (stat64(nativeEntry, &buf) != 0) {
/* Posix error occurred */
typeOk = 0;
}
}
if (typeOk) {
/*
* In order bcdpfls as in 'find -t'
|
| ︙ | | | ︙ | |
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
#endif
) {
/* Do nothing -- this file is ok */
} else {
typeOk = 0;
#ifdef S_ISLNK
if (types->type & TCL_GLOB_TYPE_LINK) {
if (lstat(nativeEntry, &buf) == 0) {
if (S_ISLNK(buf.st_mode)) {
typeOk = 1;
}
}
}
#endif
}
|
|
|
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
#endif
) {
/* Do nothing -- this file is ok */
} else {
typeOk = 0;
#ifdef S_ISLNK
if (types->type & TCL_GLOB_TYPE_LINK) {
if (lstat64(nativeEntry, &buf) == 0) {
if (S_ISLNK(buf.st_mode)) {
typeOk = 1;
}
}
}
#endif
}
|
| ︙ | | | ︙ | |
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
}
/*
*----------------------------------------------------------------------
*
* TclpObjLstat --
*
* This function replaces the library version of lstat().
*
* Results:
* See lstat() documentation.
*
* Side effects:
* See lstat() documentation.
*
*----------------------------------------------------------------------
*/
int
TclpObjLstat(pathPtr, bufPtr)
Tcl_Obj *pathPtr; /* Path of file to stat */
struct stat *bufPtr; /* Filled with results of stat call. */
{
char *path = Tcl_FSGetNativePath(pathPtr);
if (path == NULL) {
return -1;
} else {
return lstat(path, bufPtr);
}
}
/*
*---------------------------------------------------------------------------
*
* TclpObjGetCwd --
|
|
|
|
|
|
|
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
|
}
/*
*----------------------------------------------------------------------
*
* TclpObjLstat --
*
* This function replaces the library version of lstat64().
*
* Results:
* See lstat64() documentation.
*
* Side effects:
* See lstat64() documentation.
*
*----------------------------------------------------------------------
*/
int
TclpObjLstat(pathPtr, bufPtr)
Tcl_Obj *pathPtr; /* Path of file to stat */
Tcl_StatBuf *bufPtr; /* Filled with results of stat call. */
{
char *path = Tcl_FSGetNativePath(pathPtr);
if (path == NULL) {
return -1;
} else {
return lstat64(path, bufPtr);
}
}
/*
*---------------------------------------------------------------------------
*
* TclpObjGetCwd --
|
| ︙ | | | ︙ | |
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
|
}
/*
*----------------------------------------------------------------------
*
* TclpObjStat --
*
* This function replaces the library version of stat().
*
* Results:
* See stat() documentation.
*
* Side effects:
* See stat() documentation.
*
*----------------------------------------------------------------------
*/
int
TclpObjStat(pathPtr, bufPtr)
Tcl_Obj *pathPtr; /* Path of file to stat */
struct stat *bufPtr; /* Filled with results of stat call. */
{
char *path = Tcl_FSGetNativePath(pathPtr);
if (path == NULL) {
return -1;
} else {
return stat(path, bufPtr);
}
}
#ifdef S_IFLNK
Tcl_Obj*
|
|
|
|
|
|
|
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
|
}
/*
*----------------------------------------------------------------------
*
* TclpObjStat --
*
* This function replaces the library version of stat64().
*
* Results:
* See stat64() documentation.
*
* Side effects:
* See stat64() documentation.
*
*----------------------------------------------------------------------
*/
int
TclpObjStat(pathPtr, bufPtr)
Tcl_Obj *pathPtr; /* Path of file to stat */
Tcl_StatBuf *bufPtr; /* Filled with results of stat call. */
{
char *path = Tcl_FSGetNativePath(pathPtr);
if (path == NULL) {
return -1;
} else {
return stat64(path, bufPtr);
}
}
#ifdef S_IFLNK
Tcl_Obj*
|
| ︙ | | | ︙ | |