1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
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.46 2005/08/31 15:12:18 vincentdarley Exp $
* RCS: @(#) $Id: tclUnixFile.c,v 1.47 2005/11/11 23:46:36 dkf Exp $
*/
#include "tclInt.h"
#include "tclFileSystem.h"
static int NativeMatchType(CONST char* nativeName, Tcl_GlobTypeData *types);
|
| ︙ | | |
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
-
-
+
+
|
* Side effects:
* The computed path name is stored as a ProcessGlobalValue.
*
*---------------------------------------------------------------------------
*/
void
TclpFindExecutable(argv0)
CONST char *argv0; /* The value of the application's argv[0]
TclpFindExecutable(
CONST char *argv0) /* The value of the application's argv[0]
* (native). */
{
CONST char *name, *p;
Tcl_StatBuf statBuf;
Tcl_DString buffer, nameString, cwd, utfName;
Tcl_Encoding encoding;
|
| ︙ | | |
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
-
-
-
-
-
-
+
+
+
+
+
+
|
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
int
TclpMatchInDirectory(interp, resultPtr, pathPtr, pattern, types)
Tcl_Interp *interp; /* Interpreter to receive errors. */
Tcl_Obj *resultPtr; /* List object to lappend results. */
Tcl_Obj *pathPtr; /* Contains path to directory to search. */
CONST char *pattern; /* Pattern to match against. */
Tcl_GlobTypeData *types; /* Object containing list of acceptable types.
TclpMatchInDirectory(
Tcl_Interp *interp, /* Interpreter to receive errors. */
Tcl_Obj *resultPtr, /* List object to lappend results. */
Tcl_Obj *pathPtr, /* Contains path to directory to search. */
CONST char *pattern, /* Pattern to match against. */
Tcl_GlobTypeData *types) /* Object containing list of acceptable types.
* May be NULL. In particular the directory
* flag is very important. */
{
CONST char *native;
Tcl_Obj *fileNamePtr;
if (types != NULL && types->type == TCL_GLOB_TYPE_MOUNT) {
|
| ︙ | | |
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
|
-
+
|
Tcl_DecrRefCount(fileNamePtr);
return TCL_OK;
}
}
static int
NativeMatchType(
CONST char* nativeEntry, /* Native path to check. */
CONST char *nativeEntry, /* Native path to check. */
Tcl_GlobTypeData *types) /* Type description to match against. */
{
Tcl_StatBuf buf;
if (types == NULL) {
/*
* Simply check for the file's existence, but do it with lstat, in
* case it is a link to a file which doesn't exist (since that case
|
| ︙ | | |
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
|
-
-
-
+
+
+
|
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
char *
TclpGetUserHome(name, bufferPtr)
CONST char *name; /* User name for desired home directory. */
Tcl_DString *bufferPtr; /* Uninitialized or free DString filled with
TclpGetUserHome(
CONST char *name, /* User name for desired home directory. */
Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with
* name of user's home directory. */
{
struct passwd *pwPtr;
Tcl_DString ds;
CONST char *native;
native = Tcl_UtfToExternalDString(NULL, name, -1, &ds);
|
| ︙ | | |
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
-
-
-
+
+
+
|
* Side effects:
* See access() documentation.
*
*---------------------------------------------------------------------------
*/
int
TclpObjAccess(pathPtr, mode)
Tcl_Obj *pathPtr; /* Path of file to access */
int mode; /* Permission setting. */
TclpObjAccess(
Tcl_Obj *pathPtr, /* Path of file to access */
int mode) /* Permission setting. */
{
CONST char *path = Tcl_FSGetNativePath(pathPtr);
if (path == NULL) {
return -1;
} else {
return access(path, mode);
}
|
| ︙ | | |
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
|
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
|
-
-
+
+
|
* Side effects:
* See chdir() documentation.
*
*---------------------------------------------------------------------------
*/
int
TclpObjChdir(pathPtr)
Tcl_Obj *pathPtr; /* Path to new working directory */
TclpObjChdir(
Tcl_Obj *pathPtr) /* Path to new working directory */
{
CONST char *path = Tcl_FSGetNativePath(pathPtr);
if (path == NULL) {
return -1;
} else {
return chdir(path);
}
|
| ︙ | | |
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
|
-
-
-
+
+
+
|
* Side effects:
* See lstat() documentation.
*
*----------------------------------------------------------------------
*/
int
TclpObjLstat(pathPtr, bufPtr)
Tcl_Obj *pathPtr; /* Path of file to stat */
Tcl_StatBuf *bufPtr; /* Filled with results of stat call. */
TclpObjLstat(
Tcl_Obj *pathPtr, /* Path of file to stat */
Tcl_StatBuf *bufPtr) /* Filled with results of stat call. */
{
return TclOSlstat(Tcl_FSGetNativePath(pathPtr), bufPtr);
}
/*
*---------------------------------------------------------------------------
*
|
| ︙ | | |
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
-
-
+
+
|
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
ClientData
TclpGetNativeCwd(clientData)
ClientData clientData;
TclpGetNativeCwd(
ClientData clientData)
{
char buffer[MAXPATHLEN+1];
#ifdef USEGETWD
if (getwd(buffer) == NULL) /* INTL: Native. */
#else
if (getcwd(buffer, MAXPATHLEN+1) == NULL) /* INTL: Native. */
|
| ︙ | | |
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
|
-
-
-
+
+
+
-
+
|
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/
CONST char *
TclpGetCwd(interp, bufferPtr)
Tcl_Interp *interp; /* If non-NULL, used for error reporting. */
Tcl_DString *bufferPtr; /* Uninitialized or free DString filled with
TclpGetCwd(
Tcl_Interp *interp, /* If non-NULL, used for error reporting. */
Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with
* name of current directory. */
{
char buffer[MAXPATHLEN+1];
#ifdef USEGETWD
if (getwd(buffer) == NULL) /* INTL: Native. */
#else
if (getcwd(buffer, MAXPATHLEN+1) == NULL) /* INTL: Native. */
#endif
{
if (interp != NULL) {
Tcl_AppendResult(interp,
"error getting working directory name: ",
Tcl_PosixError(interp), (char *) NULL);
Tcl_PosixError(interp), NULL);
}
return NULL;
}
return Tcl_ExternalToUtfDString(NULL, buffer, -1, bufferPtr);
}
/*
|
| ︙ | | |
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
|
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
|
-
-
-
+
+
+
|
* Side effects:
* See readlink() documentation.
*
*---------------------------------------------------------------------------
*/
char *
TclpReadlink(path, linkPtr)
CONST char *path; /* Path of file to readlink (UTF-8). */
Tcl_DString *linkPtr; /* Uninitialized or free DString filled with
TclpReadlink(
CONST char *path, /* Path of file to readlink (UTF-8). */
Tcl_DString *linkPtr) /* Uninitialized or free DString filled with
* contents of link (UTF-8). */
{
#ifndef DJGPP
char link[MAXPATHLEN];
int length;
CONST char *native;
Tcl_DString ds;
|
| ︙ | | |
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
|
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
|
-
-
-
+
+
+
-
-
-
-
+
+
+
+
+
-
+
+
+
|
* Side effects:
* See stat() documentation.
*
*----------------------------------------------------------------------
*/
int
TclpObjStat(pathPtr, bufPtr)
Tcl_Obj *pathPtr; /* Path of file to stat */
Tcl_StatBuf *bufPtr; /* Filled with results of stat call. */
TclpObjStat(
Tcl_Obj *pathPtr, /* Path of file to stat */
Tcl_StatBuf *bufPtr) /* Filled with results of stat call. */
{
CONST char *path = Tcl_FSGetNativePath(pathPtr);
if (path == NULL) {
return -1;
} else {
return TclOSstat(path, bufPtr);
}
}
#ifdef S_IFLNK
Tcl_Obj*
TclpObjLink(pathPtr, toPtr, linkAction)
Tcl_Obj *pathPtr;
Tcl_Obj *toPtr;
int linkAction;
TclpObjLink(
Tcl_Obj *pathPtr,
Tcl_Obj *toPtr,
int linkAction)
{
if (toPtr != NULL) {
CONST char *src = Tcl_FSGetNativePath(pathPtr);
CONST char *target = NULL;
if (src == NULL) return NULL;
if (src == NULL) {
return NULL;
}
/*
* If we're making a symbolic link and the path is relative, then we
* must check whether it exists _relative_ to the directory in which
* the src is found (not relative to the current cwd which is just not
* relevant in this case).
*
|
| ︙ | | |
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
|
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
|
-
+
|
}
} else {
errno = ENODEV;
return NULL;
}
return toPtr;
} else {
Tcl_Obj* linkPtr = NULL;
Tcl_Obj *linkPtr = NULL;
char link[MAXPATHLEN];
int length;
Tcl_DString ds;
Tcl_Obj *transPtr;
transPtr = Tcl_FSGetTranslatedPath(NULL, pathPtr);
|
| ︙ | | |
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
|
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
|
-
-
-
+
+
+
|
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
Tcl_Obj*
TclpFilesystemPathType(pathPtr)
Tcl_Obj* pathPtr;
Tcl_Obj *
TclpFilesystemPathType(
Tcl_Obj *pathPtr)
{
/*
* All native paths are of the same type.
*/
return NULL;
}
|
| ︙ | | |
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
|
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
|
-
-
-
+
+
+
|
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
Tcl_Obj*
TclpNativeToNormalized(clientData)
ClientData clientData;
Tcl_Obj *
TclpNativeToNormalized(
ClientData clientData)
{
Tcl_DString ds;
Tcl_Obj *objPtr;
int len;
CONST char *copy;
Tcl_ExternalToUtfDString(NULL, (CONST char*)clientData, -1, &ds);
|
| ︙ | | |
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
|
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
|
-
+
-
-
+
+
-
+
|
*
* Create a native representation for the given path.
*
* Results:
* The nativePath representation.
*
* Side effects:
* Memory will be allocated. The path may need to be normalized.
* Memory will be allocated. The path may need to be normalized.
*
*---------------------------------------------------------------------------
*/
ClientData
TclNativeCreateNativeRep(pathPtr)
Tcl_Obj* pathPtr;
TclNativeCreateNativeRep(
Tcl_Obj *pathPtr)
{
char *nativePathPtr;
Tcl_DString ds;
Tcl_Obj* validPathPtr;
Tcl_Obj *validPathPtr;
int len;
char *str;
if (TclFSCwdIsNative()) {
/*
* The cwd is native, which means we can use the translated path
* without worrying about normalization (this will also usually be
|
| ︙ | | |
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
|
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
|
-
+
|
}
str = Tcl_GetStringFromObj(validPathPtr, &len);
Tcl_UtfToExternalDString(NULL, str, len, &ds);
len = Tcl_DStringLength(&ds) + sizeof(char);
Tcl_DecrRefCount(validPathPtr);
nativePathPtr = ckalloc((unsigned) len);
memcpy((VOID*)nativePathPtr, (VOID*)Tcl_DStringValue(&ds), (size_t) len);
memcpy((void*)nativePathPtr, (void*)Tcl_DStringValue(&ds), (size_t) len);
Tcl_DStringFree(&ds);
return (ClientData)nativePathPtr;
}
/*
*---------------------------------------------------------------------------
|
| ︙ | | |
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
|
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
|
-
-
+
+
-
+
-
-
-
+
+
+
|
* Side effects:
* Memory will be allocated for the copy.
*
*---------------------------------------------------------------------------
*/
ClientData
TclNativeDupInternalRep(clientData)
ClientData clientData;
TclNativeDupInternalRep(
ClientData clientData)
{
char *copy;
size_t len;
if (clientData == NULL) {
return NULL;
}
/*
* ASCII representation when running on Unix.
*/
len = sizeof(char) + (strlen((CONST char*) clientData) * sizeof(char));
copy = (char *) ckalloc(len);
memcpy((VOID *) copy, (VOID *) clientData, len);
memcpy((void *) copy, (void *) clientData, len);
return (ClientData)copy;
}
/*
*---------------------------------------------------------------------------
*
* TclpUtime --
*
* Set the modification date for a file.
*
* Results:
* 0 on success, -1 on error.
*
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
int
TclpUtime(pathPtr, tval)
Tcl_Obj *pathPtr; /* File to modify */
struct utimbuf *tval; /* New modification date structure */
TclpUtime(
Tcl_Obj *pathPtr, /* File to modify */
struct utimbuf *tval) /* New modification date structure */
{
return utime(Tcl_FSGetNativePath(pathPtr), tval);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|