Diff
Not logged in

Differences From Artifact [8fa31fbc8e]:

To Artifact [b1f7724b3a]:


1047
1048
1049
1050
1051
1052
1053
1054
1055


1056
1057
1058
1059
1060
1061
1062
1063
1047
1048
1049
1050
1051
1052
1053


1054
1055

1056
1057
1058
1059
1060
1061
1062







-
-
+
+
-







     * generic code because otherwise every filesystem implementation of
     * Tcl_FSMatchInDirectory has to do it.
     */

    cwd = Tcl_FSGetCwd(NULL);
    if (cwd == NULL) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "glob couldn't determine the current working directory",
	    TclPrintfResult(interp,
		    "glob couldn't determine the current working directory");
		    -1));
	}
	return TCL_ERROR;
    }

    fsPtr = Tcl_FSGetFileSystemForPath(cwd);
    if (fsPtr != NULL && fsPtr->matchInDirectoryProc != NULL) {
	TclNewObj(tmpResultPtr);
1509
1510
1511
1512
1513
1514
1515
1516
1517

1518
1519
1520
1521
1522
1523
1524
1508
1509
1510
1511
1512
1513
1514


1515
1516
1517
1518
1519
1520
1521
1522







-
-
+







	    goto error;
	}
	return mode;

    error:
	*modeFlagsPtr = 0;
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "illegal access mode \"%s\"", modeString));
	    TclPrintfResult(interp, "illegal access mode \"%s\"", modeString);
	    Tcl_SetErrorCode(interp, "TCL", "OPENMODE", "INVALID", (char *)NULL);
	}
	return -1;
    }

    /*
     * The access modes are specified as a list of POSIX modes like O_CREAT.
1545
1546
1547
1548
1549
1550
1551
1552

1553
1554

1555
1556
1557
1558
1559
1560
1561
1543
1544
1545
1546
1547
1548
1549

1550
1551

1552
1553
1554
1555
1556
1557
1558
1559







-
+

-
+







    for (i = 0; i < modeArgc; i++) {
	flag = modeArgv[i];
	c = flag[0];
	if ((c == 'R') && (strcmp(flag, "RDONLY") == 0)) {
	    if (gotRW) {
	    invRW:
		if (interp != NULL) {
		    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    TclPrintfResult(interp,
				"invalid access mode \"%s\": modes RDONLY, "
				"RDWR, and WRONLY cannot be combined", flag));
				"RDWR, and WRONLY cannot be combined", flag);
		}
		goto invAccessMode;
	    }
	    mode = (mode & ~O_ACCMODE) | O_RDONLY;
	    gotRW = 1;
	} else if ((c == 'W') && (strcmp(flag, "WRONLY") == 0)) {
	    if (gotRW) {
1569
1570
1571
1572
1573
1574
1575
1576
1577


1578
1579

1580
1581
1582
1583
1584
1585

1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601

1602
1603

1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616

1617
1618

1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634

1635
1636
1637

1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648


1649
1650
1651
1652
1653
1654
1655
1656
1567
1568
1569
1570
1571
1572
1573


1574
1575
1576

1577
1578
1579
1580
1581
1582

1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598

1599
1600

1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613

1614
1615

1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631

1632
1633
1634

1635
1636
1637
1638
1639
1640
1641
1642
1643
1644


1645
1646

1647
1648
1649
1650
1651
1652
1653







-
-
+
+

-
+





-
+















-
+

-
+












-
+

-
+















-
+


-
+









-
-
+
+
-







	    }
	    mode = (mode & ~O_ACCMODE) | O_RDWR;
	    gotRW = 1;
	} else if ((c == 'A') && (strcmp(flag, "APPEND") == 0)) {
	    if (mode & O_APPEND) {
	    accessFlagRepeated:
		if (interp) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
			"access mode \"%s\" repeated", flag));
		    TclPrintfResult(interp,
			    "access mode \"%s\" repeated", flag);
		}
	    goto invAccessMode;
		goto invAccessMode;
	    }
	    mode |= O_APPEND;
	    *modeFlagsPtr |= 1;
	} else if ((c == 'C') && (strcmp(flag, "CREAT") == 0)) {
	    if (mode & O_CREAT) {
	    goto accessFlagRepeated;
		goto accessFlagRepeated;
	    }
	    mode |= O_CREAT;
	} else if ((c == 'E') && (strcmp(flag, "EXCL") == 0)) {
	    if (mode & O_EXCL) {
		goto accessFlagRepeated;
	    }
	    mode |= O_EXCL;
	} else if ((c == 'N') && (strcmp(flag, "NOCTTY") == 0)) {
#ifdef O_NOCTTY
	    if (mode & O_NOCTTY) {
		goto accessFlagRepeated;
	    }
	    mode |= O_NOCTTY;
#else
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"access mode \"%s\" not supported by this system",
			flag));
			flag);
	    }
	    goto invAccessMode;
#endif

	} else if ((c == 'N') && (strcmp(flag, "NONBLOCK") == 0)) {
#ifdef O_NONBLOCK
	    if (mode & O_NONBLOCK) {
		goto accessFlagRepeated;
	    }
	    mode |= O_NONBLOCK;
#else
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"access mode \"%s\" not supported by this system",
			flag));
			flag);
	    }
	    goto invAccessMode;
#endif
	} else if ((c == 'T') && (strcmp(flag, "TRUNC") == 0)) {
	    if (mode & O_TRUNC) {
		goto accessFlagRepeated;
	    }
	    mode |= O_TRUNC;
	} else if ((c == 'B') && (strcmp(flag, "BINARY") == 0)) {
	    if (*modeFlagsPtr & CHANNEL_RAW_MODE) {
		goto accessFlagRepeated;
	    }
	    *modeFlagsPtr |= CHANNEL_RAW_MODE;
	} else {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"invalid access mode \"%s\": must be APPEND, BINARY, "
			"CREAT, EXCL, NOCTTY, NONBLOCK, RDONLY, RDWR, "
			"TRUNC, or WRONLY", flag));
			"TRUNC, or WRONLY", flag);
	    }
	    goto invAccessMode;
	}
    }

    Tcl_Free((void *)modeArgv);

    if (!gotRW) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "access mode must include either RDONLY, RDWR, or WRONLY",
	    TclPrintfResult(interp,
		    "access mode must include either RDONLY, RDWR, or WRONLY");
		    -1));
	}
	return -1;
    }
    return mode;
}

/*
1706
1707
1708
1709
1710
1711
1712
1713

1714
1715

1716
1717
1718
1719
1720

1721
1722

1723
1724
1725
1726
1727
1728
1729
1703
1704
1705
1706
1707
1708
1709

1710
1711

1712
1713
1714
1715
1716

1717
1718

1719
1720
1721
1722
1723
1724
1725
1726







-
+

-
+




-
+

-
+








    if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) {
	return result;
    }

    if (Tcl_FSStat(pathPtr, &statBuf) == -1) {
	Tcl_SetErrno(errno);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
		TclGetString(pathPtr), Tcl_PosixError(interp));
	return result;
    }
    chan = Tcl_FSOpenFileChannel(interp, pathPtr, "r", 0644);
    if (chan == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
		TclGetString(pathPtr), Tcl_PosixError(interp));
	return result;
    }

    /*
     * The eof character is \x1A (^Z). Tcl uses it on every platform to allow
     * for scripted documents. [Bug: 2040]
     */
1749
1750
1751
1752
1753
1754
1755
1756

1757
1758

1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771

1772
1773

1774
1775
1776
1777
1778
1779
1780
1746
1747
1748
1749
1750
1751
1752

1753
1754

1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767

1768
1769

1770
1771
1772
1773
1774
1775
1776
1777







-
+

-
+












-
+

-
+








    /*
     * Read first character of stream to check for utf-8 BOM
     */

    if (Tcl_ReadChars(chan, objPtr, 1, 0) == TCL_IO_FAILURE) {
	Tcl_CloseEx(interp, chan, 0);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
		TclGetString(pathPtr), Tcl_PosixError(interp));
	goto end;
    }
    string = TclGetString(objPtr);

    /*
     * If first character is not a BOM, append the remaining characters.
     * Otherwise, replace them. [Bug 3466099]
     */

    if (Tcl_ReadChars(chan, objPtr, TCL_INDEX_NONE,
	    memcmp(string, "\xEF\xBB\xBF", 3)) == TCL_IO_FAILURE) {
	Tcl_CloseEx(interp, chan, 0);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	TclPrintfResult(interp,
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
		TclGetString(pathPtr), Tcl_PosixError(interp));
	goto end;
    }

    if (Tcl_CloseEx(interp, chan, 0) != TCL_OK) {
	goto end;
    }

1841
1842
1843
1844
1845
1846
1847
1848
1849
1850


1851
1852
1853
1854
1855
1856
1857


1858
1859
1860
1861
1862
1863
1864
1838
1839
1840
1841
1842
1843
1844



1845
1846
1847
1848
1849
1850



1851
1852
1853
1854
1855
1856
1857
1858
1859







-
-
-
+
+




-
-
-
+
+








    if (Tcl_FSGetNormalizedPath(interp, pathPtr) == NULL) {
	return TCL_ERROR;
    }

    if (Tcl_FSStat(pathPtr, &statBuf) == -1) {
	Tcl_SetErrno(errno);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
	TclPrintfResult(interp, "couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp));
	return TCL_ERROR;
    }
    chan = Tcl_FSOpenFileChannel(interp, pathPtr, "r", 0644);
    if (chan == NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
	TclPrintfResult(interp, "couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp));
	return TCL_ERROR;
    }
    TclPkgFileSeen(interp, TclGetString(pathPtr));

    /*
     * The eof character is \x1A (^Z). Tcl uses it on every platform to allow
     * for scripted documents. [Bug: 2040]
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894


1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910


1911
1912
1913
1914
1915
1916
1917
1880
1881
1882
1883
1884
1885
1886



1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901



1902
1903
1904
1905
1906
1907
1908
1909
1910







-
-
-
+
+













-
-
-
+
+








    /*
     * Read first character of stream to check for utf-8 BOM
     */

    if (Tcl_ReadChars(chan, objPtr, 1, 0) == TCL_IO_FAILURE) {
	Tcl_CloseEx(interp, chan, 0);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
	TclPrintfResult(interp, "couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp));
	Tcl_DecrRefCount(objPtr);
	return TCL_ERROR;
    }
    string = TclGetString(objPtr);

    /*
     * If first character is not a BOM, append the remaining characters.
     * Otherwise, replace them. [Bug 3466099]
     */

    if (Tcl_ReadChars(chan, objPtr, TCL_INDEX_NONE,
	    memcmp(string, "\xEF\xBB\xBF", 3)) == TCL_IO_FAILURE) {
	Tcl_CloseEx(interp, chan, 0);
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
	TclPrintfResult(interp, "couldn't read file \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp));
	Tcl_DecrRefCount(objPtr);
	return TCL_ERROR;
    }

    if (Tcl_CloseEx(interp, chan, 0) != TCL_OK) {
	Tcl_DecrRefCount(objPtr);
	return TCL_ERROR;
2226
2227
2228
2229
2230
2231
2232
2233

2234
2235

2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254


2255
2256
2257
2258
2259
2260
2261
2219
2220
2221
2222
2223
2224
2225

2226
2227

2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244



2245
2246
2247
2248
2249
2250
2251
2252
2253







-
+

-
+
















-
-
-
+
+







	/*
	 * Seek and/or set binary mode as determined above.
	 */

	if ((modeFlags & 1) && Tcl_Seek(retVal, (Tcl_WideInt) 0, SEEK_END)
		< (Tcl_WideInt) 0) {
	    if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"could not seek to end of file while opening \"%s\": %s",
			TclGetString(pathPtr), Tcl_PosixError(interp)));
			TclGetString(pathPtr), Tcl_PosixError(interp));
	    }
	    Tcl_CloseEx(NULL, retVal, 0);
	    return NULL;
	}
	if (modeFlags & CHANNEL_RAW_MODE) {
	    Tcl_SetChannelOption(interp, retVal, "-translation", "binary");
	}
	return retVal;
    }

    /*
     * File doesn't belong to any filesystem that can open it.
     */

    Tcl_SetErrno(ENOENT);
    if (interp != NULL) {
	Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		"couldn't open \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp)));
	TclPrintfResult(interp, "couldn't open \"%s\": %s",
		TclGetString(pathPtr), Tcl_PosixError(interp));
    }
    return NULL;
}

/*
 *----------------------------------------------------------------------
 *
2670
2671
2672
2673
2674
2675
2676
2677

2678
2679

2680
2681
2682
2683
2684
2685
2686
2662
2663
2664
2665
2666
2667
2668

2669
2670

2671
2672
2673
2674
2675
2676
2677
2678







-
+

-
+







		    fsRecPtr->fsPtr->freeInternalRepProc(retCd);
		}
		Tcl_DecrRefCount(retVal);
		retVal = NULL;
		Disclaim();
		goto cdDidNotChange;
	    } else if (interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"error getting working directory name: %s",
			Tcl_PosixError(interp)));
			Tcl_PosixError(interp));
	    }
	}
	Disclaim();

	if (retVal != NULL) {
	    /*
	     * On some platforms the pathname of the current directory might
2745
2746
2747
2748
2749
2750
2751
2752

2753
2754

2755
2756
2757
2758
2759
2760
2761
2737
2738
2739
2740
2741
2742
2743

2744
2745

2746
2747
2748
2749
2750
2751
2752
2753







-
+

-
+







	     * New API.
	     */

	    TclFSGetCwdProc2 *proc2 = (TclFSGetCwdProc2 *) fsPtr->getCwdProc;

	    retCd = proc2(tsdPtr->cwdClientData);
	    if (retCd == NULL && interp != NULL) {
		Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		TclPrintfResult(interp,
			"error getting working directory name: %s",
			Tcl_PosixError(interp)));
			Tcl_PosixError(interp));
	    }

	    if (retCd == tsdPtr->cwdClientData) {
		goto cdDidNotChange;
	    }

	    /*
3207
3208
3209
3210
3211
3212
3213
3214

3215
3216

3217
3218
3219
3220
3221
3222
3223
3199
3200
3201
3202
3203
3204
3205

3206
3207

3208
3209
3210
3211
3212
3213
3214
3215







-
+

-
+








    /*
     * Make sure the file is accessible.
     */

    if (Tcl_FSAccess(pathPtr, R_OK) != 0) {
	if (interp) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
	    TclPrintfResult(interp,
		    "couldn't load library \"%s\": %s",
		    TclGetString(pathPtr), Tcl_PosixError(interp)));
		    TclGetString(pathPtr), Tcl_PosixError(interp));
	}
	return TCL_ERROR;
    }

#ifdef TCL_LOAD_FROM_MEMORY
    /*
     * The platform supports loading a dynamic shared object from memory.
3283
3284
3285
3286
3287
3288
3289
3290
3291

3292
3293
3294
3295
3296
3297
3298
3275
3276
3277
3278
3279
3280
3281


3282
3283
3284
3285
3286
3287
3288
3289







-
-
+







	 /*
	  * Try to delete the file we probably created and then exit.
	  */

	Tcl_FSDeleteFile(copyToPtr);
	Tcl_DecrRefCount(copyToPtr);
	if (interp) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "couldn't load from current filesystem", -1));
	    TclPrintfResult(interp, "couldn't load from current filesystem");
	}
	return TCL_ERROR;
    }

    if (TclCrossFilesystemCopy(interp, pathPtr, copyToPtr) != TCL_OK) {
	Tcl_FSDeleteFile(copyToPtr);
	Tcl_DecrRefCount(copyToPtr);
3584
3585
3586
3587
3588
3589
3590
3591
3592


3593
3594
3595
3596
3597
3598
3599
3600
3575
3576
3577
3578
3579
3580
3581


3582
3583

3584
3585
3586
3587
3588
3589
3590







-
-
+
+
-







int
Tcl_FSUnloadFile(
    Tcl_Interp *interp,		/* The relevant interpreter. */
    Tcl_LoadHandle handle)	/* A handle for the object to unload. */
{
    if (handle->unloadFileProcPtr == NULL) {
	if (interp != NULL) {
	    Tcl_SetObjResult(interp, Tcl_NewStringObj(
		    "cannot unload: filesystem does not support unloading",
	    TclPrintfResult(interp,
		    "cannot unload: filesystem does not support unloading");
		    -1));
	}
	return TCL_ERROR;
    }
    if (handle->unloadFileProcPtr != NULL) {
	handle->unloadFileProcPtr(handle);
    }
    return TCL_OK;
3844
3845
3846
3847
3848
3849
3850
3851
3852

3853
3854
3855
3856
3857
3858
3859
3834
3835
3836
3837
3838
3839
3840


3841
3842
3843
3844
3845
3846
3847
3848







-
-
+







	Tcl_Size length;

	while ((*p != '\0') && (*p != separator)) {
	    p++;
	}
	length = p - elementStart;
	if (length > 0) {
	    Tcl_Obj *nextElt;
	    nextElt = Tcl_NewStringObj(elementStart, length);
	    Tcl_Obj *nextElt = Tcl_NewStringObj(elementStart, length);
	    Tcl_ListObjAppendElement(NULL, result, nextElt);
	}
	if (*p++ == '\0') {
	    break;
	}
    }