| ︙ | | | ︙ | |
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
*
* Copyright (c) 1991-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 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: tclIOUtil.c,v 1.81.2.5 2004/02/07 05:48:01 dgp Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
#ifdef MAC_TCL
#include "tclMacInt.h"
#endif
#ifdef __WIN32__
/* for tclWinProcs->useWide */
#include "tclWinInt.h"
#endif
#include "tclFileSystem.h"
/*
|
|
<
<
<
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
*
* Copyright (c) 1991-1994 The Regents of the University of California.
* Copyright (c) 1994-1997 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: tclIOUtil.c,v 1.81.2.6 2004/03/26 22:28:26 dgp Exp $
*/
#include "tclInt.h"
#include "tclPort.h"
#ifdef __WIN32__
/* for tclWinProcs->useWide */
#include "tclWinInt.h"
#endif
#include "tclFileSystem.h"
/*
|
| ︙ | | | ︙ | |
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#ifdef TCL_THREADS
static void FsRecacheFilesystemList(void);
#endif
/*
* These form part of the native filesystem support. They are needed
* here because we have a few native filesystem functions (which are
* the same for mac/win/unix) in this file. There is no need to place
* them in tclInt.h, because they are not (and should not be) used
* anywhere else.
*/
extern CONST char * tclpFileAttrStrings[];
extern CONST TclFileAttrProcs tclpFileAttrProcs[];
/*
|
|
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#ifdef TCL_THREADS
static void FsRecacheFilesystemList(void);
#endif
/*
* These form part of the native filesystem support. They are needed
* here because we have a few native filesystem functions (which are
* the same for win/unix) in this file. There is no need to place
* them in tclInt.h, because they are not (and should not be) used
* anywhere else.
*/
extern CONST char * tclpFileAttrStrings[];
extern CONST TclFileAttrProcs tclpFileAttrProcs[];
/*
|
| ︙ | | | ︙ | |
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
static Tcl_FSCreateInternalRepProc NativeCreateNativeRep;
static Tcl_FSFileAttrStringsProc NativeFileAttrStrings;
static Tcl_FSFileAttrsGetProc NativeFileAttrsGet;
static Tcl_FSFileAttrsSetProc NativeFileAttrsSet;
/*
* The only reason these functions are not static is that they
* are either called by code in the native (win/unix/mac) directories
* or they are actually implemented in those directories. They
* should simply not be called by code outside Tcl's native
* filesystem core. i.e. they should be considered 'static' to
* Tcl's filesystem code (if we ever built the native filesystem
* support into a separate code library, this could actually be
* enforced).
*/
|
|
|
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
|
static Tcl_FSCreateInternalRepProc NativeCreateNativeRep;
static Tcl_FSFileAttrStringsProc NativeFileAttrStrings;
static Tcl_FSFileAttrsGetProc NativeFileAttrsGet;
static Tcl_FSFileAttrsSetProc NativeFileAttrsSet;
/*
* The only reason these functions are not static is that they
* are either called by code in the native (win/unix) directories
* or they are actually implemented in those directories. They
* should simply not be called by code outside Tcl's native
* filesystem core. i.e. they should be considered 'static' to
* Tcl's filesystem code (if we ever built the native filesystem
* support into a separate code library, this could actually be
* enforced).
*/
|
| ︙ | | | ︙ | |
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
|
*---------------------------------------------------------------------------
*
* TclFSNormalizeToUniquePath --
*
* Description:
* Takes a path specification containing no ../, ./ sequences,
* and converts it into a unique path for the given platform.
* On MacOS, Unix, this means the path must be free of
* symbolic links/aliases, and on Windows it means we want the
* long form, with that long form's case-dependence (which gives
* us a unique, case-dependent path).
*
* Results:
* The pathPtr is modified in place. The return value is
* the last byte offset which was recognised in the path
* string.
*
* Side effects:
* None (beyond the memory allocation for the result).
*
* Special notes:
* If the filesystem-specific normalizePathProcs can re-introduce
* ../, ./ sequences into the path, then this function will
* not return the correct result. This may be possible with
* symbolic links on unix/macos.
*
* Important assumption: if startAt is non-zero, it must point
* to a directory separator that we know exists and is already
* normalized (so it is important not to point to the char just
* after the separator).
*---------------------------------------------------------------------------
*/
|
|
|
|
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
|
*---------------------------------------------------------------------------
*
* TclFSNormalizeToUniquePath --
*
* Description:
* Takes a path specification containing no ../, ./ sequences,
* and converts it into a unique path for the given platform.
* On Unix, this means the path must be free of
* symbolic links/aliases, and on Windows it means we want the
* long form, with that long form's case-dependence (which gives
* us a unique, case-dependent path).
*
* Results:
* The pathPtr is modified in place. The return value is
* the last byte offset which was recognised in the path
* string.
*
* Side effects:
* None (beyond the memory allocation for the result).
*
* Special notes:
* If the filesystem-specific normalizePathProcs can re-introduce
* ../, ./ sequences into the path, then this function will
* not return the correct result. This may be possible with
* symbolic links on unix.
*
* Important assumption: if startAt is non-zero, it must point
* to a directory separator that we know exists and is already
* normalized (so it is important not to point to the char just
* after the separator).
*---------------------------------------------------------------------------
*/
|
| ︙ | | | ︙ | |
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
|
*
* NativeFileAttrStrings --
*
* This procedure implements the platform dependent 'file
* attributes' subcommand, for the native filesystem, for listing
* the set of possible attribute strings. This function is part
* of Tcl's native filesystem support, and is placed here because
* it is shared by Unix, MacOS and Windows code.
*
* Results:
* An array of strings
*
* Side effects:
* None.
*
|
|
|
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
|
*
* NativeFileAttrStrings --
*
* This procedure implements the platform dependent 'file
* attributes' subcommand, for the native filesystem, for listing
* the set of possible attribute strings. This function is part
* of Tcl's native filesystem support, and is placed here because
* it is shared by Unix and Windows code.
*
* Results:
* An array of strings
*
* Side effects:
* None.
*
|
| ︙ | | | ︙ | |
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
|
*
* NativeFileAttrsGet --
*
* This procedure implements the platform dependent
* 'file attributes' subcommand, for the native
* filesystem, for 'get' operations. This function is part
* of Tcl's native filesystem support, and is placed here
* because it is shared by Unix, MacOS and Windows code.
*
* Results:
* Standard Tcl return code. The object placed in objPtrRef
* (if TCL_OK was returned) is likely to have a refCount of zero.
* Either way we must either store it somewhere (e.g. the Tcl
* result), or Incr/Decr its refCount to ensure it is properly
* freed.
|
|
|
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
|
*
* NativeFileAttrsGet --
*
* This procedure implements the platform dependent
* 'file attributes' subcommand, for the native
* filesystem, for 'get' operations. This function is part
* of Tcl's native filesystem support, and is placed here
* because it is shared by Unix and Windows code.
*
* Results:
* Standard Tcl return code. The object placed in objPtrRef
* (if TCL_OK was returned) is likely to have a refCount of zero.
* Either way we must either store it somewhere (e.g. the Tcl
* result), or Incr/Decr its refCount to ensure it is properly
* freed.
|
| ︙ | | | ︙ | |
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
|
*
* NativeFileAttrsSet --
*
* This procedure implements the platform dependent
* 'file attributes' subcommand, for the native
* filesystem, for 'set' operations. This function is part
* of Tcl's native filesystem support, and is placed here
* because it is shared by Unix, MacOS and Windows code.
*
* Results:
* Standard Tcl return code.
*
* Side effects:
* None.
*
|
|
|
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
|
*
* NativeFileAttrsSet --
*
* This procedure implements the platform dependent
* 'file attributes' subcommand, for the native
* filesystem, for 'set' operations. This function is part
* of Tcl's native filesystem support, and is placed here
* because it is shared by Unix and Windows code.
*
* Results:
* Standard Tcl return code.
*
* Side effects:
* None.
*
|
| ︙ | | | ︙ | |
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
|
copyToPtr) == TCL_OK) {
Tcl_LoadHandle newLoadHandle = NULL;
ClientData newClientData = NULL;
Tcl_FSUnloadFileProc *newUnloadProcPtr = NULL;
FsDivertLoad *tvdlPtr;
int retVal;
#if !defined(__WIN32__) && !defined(MAC_TCL)
/*
* Do we need to set appropriate permissions
* on the file? This may be required on some
* systems. On Unix we could loop over
* the file attributes, and set any that are
* called "-permissions" to 0700. However,
* we just do this directly, like this:
|
|
|
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
|
copyToPtr) == TCL_OK) {
Tcl_LoadHandle newLoadHandle = NULL;
ClientData newClientData = NULL;
Tcl_FSUnloadFileProc *newUnloadProcPtr = NULL;
FsDivertLoad *tvdlPtr;
int retVal;
#if !defined(__WIN32__)
/*
* Do we need to set appropriate permissions
* on the file? This may be required on some
* systems. On Unix we could loop over
* the file attributes, and set any that are
* called "-permissions" to 0700. However,
* we just do this directly, like this:
|
| ︙ | | | ︙ | |
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
|
fsRecPtr = FsGetFirstFilesystem();
while (fsRecPtr != NULL) {
Tcl_FSListVolumesProc *proc = fsRecPtr->fsPtr->listVolumesProc;
/*
* We want to skip the native filesystem in this loop because
* otherwise we won't necessarily pass all the Tcl testsuite --
* this is because some of the tests artificially change the
* current platform (between mac, win, unix) but the list
* of volumes we get by calling (*proc) will reflect the current
* (real) platform only and this may cause some tests to fail.
* In particular, on unix '/' will match the beginning of
* certain absolute Windows paths starting '//' and those tests
* will go wrong.
*
* Besides these test-suite issues, there is one other reason
|
|
|
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
|
fsRecPtr = FsGetFirstFilesystem();
while (fsRecPtr != NULL) {
Tcl_FSListVolumesProc *proc = fsRecPtr->fsPtr->listVolumesProc;
/*
* We want to skip the native filesystem in this loop because
* otherwise we won't necessarily pass all the Tcl testsuite --
* this is because some of the tests artificially change the
* current platform (between win, unix) but the list
* of volumes we get by calling (*proc) will reflect the current
* (real) platform only and this may cause some tests to fail.
* In particular, on unix '/' will match the beginning of
* certain absolute Windows paths starting '//' and those tests
* will go wrong.
*
* Besides these test-suite issues, there is one other reason
|
| ︙ | | | ︙ | |
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
|
}
/*
*---------------------------------------------------------------------------
*
* Tcl_FSGetNativePath --
*
* This function is for use by the Win/Unix/MacOS native filesystems,
* so that they can easily retrieve the native (char* or TCHAR*)
* representation of a path. Other filesystems will probably
* want to implement similar functions. They basically act as a
* safety net around Tcl_FSGetInternalRep. Normally your file-
* system procedures will always be called with path objects
* already converted to the correct filesystem, but if for
* some reason they are called directly (i.e. by procedures
* not in this file), then one cannot necessarily guarantee that
* the path object pointer is from the correct filesystem.
*
* Note: in the future it might be desireable to have separate
* versions of this function with different signatures, for
* example Tcl_FSGetNativeMacPath, Tcl_FSGetNativeUnixPath etc.
* Right now, since native paths are all string based, we use just
* one function. On MacOS we could possibly use an FSSpec or
* FSRef as the native representation.
*
* Results:
* NULL or a valid native path.
*
* Side effects:
* See Tcl_FSGetInternalRep.
*
|
|
|
|
<
|
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
|
}
/*
*---------------------------------------------------------------------------
*
* Tcl_FSGetNativePath --
*
* This function is for use by the Win/Unix native filesystems,
* so that they can easily retrieve the native (char* or TCHAR*)
* representation of a path. Other filesystems will probably
* want to implement similar functions. They basically act as a
* safety net around Tcl_FSGetInternalRep. Normally your file-
* system procedures will always be called with path objects
* already converted to the correct filesystem, but if for
* some reason they are called directly (i.e. by procedures
* not in this file), then one cannot necessarily guarantee that
* the path object pointer is from the correct filesystem.
*
* Note: in the future it might be desireable to have separate
* versions of this function with different signatures, for
* example Tcl_FSGetNativeWinPath, Tcl_FSGetNativeUnixPath etc.
* Right now, since native paths are all string based, we use just
* one function.
*
* Results:
* NULL or a valid native path.
*
* Side effects:
* See Tcl_FSGetInternalRep.
*
|
| ︙ | | | ︙ | |
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
|
/* unicode representation when running on NT/2K/XP */
len = sizeof(WCHAR) + (wcslen((CONST WCHAR*)clientData) * sizeof(WCHAR));
} else {
/* ansi representation when running on 95/98/ME */
len = sizeof(char) + (strlen((CONST char*)clientData) * sizeof(char));
}
#else
/* ansi representation when running on Unix/MacOS */
len = sizeof(char) + (strlen((CONST char*)clientData) * sizeof(char));
#endif
copy = (char *) ckalloc(len);
memcpy((VOID*)copy, (VOID*)clientData, len);
return (ClientData)copy;
}
|
|
|
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
|
/* unicode representation when running on NT/2K/XP */
len = sizeof(WCHAR) + (wcslen((CONST WCHAR*)clientData) * sizeof(WCHAR));
} else {
/* ansi representation when running on 95/98/ME */
len = sizeof(char) + (strlen((CONST char*)clientData) * sizeof(char));
}
#else
/* ansi representation when running on Unix */
len = sizeof(char) + (strlen((CONST char*)clientData) * sizeof(char));
#endif
copy = (char *) ckalloc(len);
memcpy((VOID*)copy, (VOID*)clientData, len);
return (ClientData)copy;
}
|
| ︙ | | | ︙ | |
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
|
switch (tclPlatform) {
case TCL_PLATFORM_UNIX:
separator = "/";
break;
case TCL_PLATFORM_WINDOWS:
separator = "\\";
break;
case TCL_PLATFORM_MAC:
separator = ":";
break;
}
return Tcl_NewStringObj(separator,1);
}
/* Everything from here on is contained in this obsolete ifdef */
#ifdef USE_OBSOLETE_FS_HOOKS
|
<
<
<
|
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
|
switch (tclPlatform) {
case TCL_PLATFORM_UNIX:
separator = "/";
break;
case TCL_PLATFORM_WINDOWS:
separator = "\\";
break;
}
return Tcl_NewStringObj(separator,1);
}
/* Everything from here on is contained in this obsolete ifdef */
#ifdef USE_OBSOLETE_FS_HOOKS
|
| ︙ | | | ︙ | |