Diff
Not logged in

Differences From Artifact [bfe3b54142]:

To Artifact [534abcc1cc]:


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.4 2001/09/27 15:18:52 dkf 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.5 2001/09/27 15:48:17 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) {
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

	/*
	 * 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 = "./";







|
|







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

	/*
	 * 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. */
		&& (Tcl_PlatformStat(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 ((Tcl_PlatformStat(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
	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







|










|







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
	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 (Tcl_PlatformStat(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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
			)) {
			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'







|







373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
			)) {
			typeOk = 0;
		    }
		}
		if (typeOk && (types->type != 0)) {
		    if (types->perm == 0) {
			/* We haven't yet done a stat on the file */
			if (Tcl_PlatformStat(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 (Tcl_PlatformLStat(nativeEntry, &buf)==0) {
				    if (S_ISLNK(buf.st_mode)) {
				        typeOk = 1;
				    }
				}
			    }
#endif
			}
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
    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 --







|







554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
    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 Tcl_PlatformLStat(path, bufPtr);
    }
}

/*
 *---------------------------------------------------------------------------
 *
 * TclpObjGetCwd --
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
    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* 







|







686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
    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 Tcl_PlatformStat(path, bufPtr);
    }
}


#ifdef S_IFLNK

Tcl_Obj* 
730
731
732
733
734
735
736
737
738
739
	linkPtr = Tcl_FSNewNativePath(pathPtr, native);
	Tcl_IncrRefCount(linkPtr);
    }
    return linkPtr;
}

#endif










<
<
<
730
731
732
733
734
735
736



	linkPtr = Tcl_FSNewNativePath(pathPtr, native);
	Tcl_IncrRefCount(linkPtr);
    }
    return linkPtr;
}

#endif