summaryrefslogtreecommitdiffstats
path: root/macosx/tclMacOSXFCmd.c
diff options
context:
space:
mode:
authordas <das>2005-11-27 02:33:48 (GMT)
committerdas <das>2005-11-27 02:33:48 (GMT)
commit869ae625bcbb07adbc4ebdbea88b0997540c0eb4 (patch)
tree0b3ddbb9d4e905eaba0c0baa102ace44b84277a5 /macosx/tclMacOSXFCmd.c
parent4108d5e746022cd525e93215aeb41eb0a1ab3b7a (diff)
downloadtcl-869ae625bcbb07adbc4ebdbea88b0997540c0eb4.zip
tcl-869ae625bcbb07adbc4ebdbea88b0997540c0eb4.tar.gz
tcl-869ae625bcbb07adbc4ebdbea88b0997540c0eb4.tar.bz2
* unix/tcl.m4 (Darwin): add 64bit support, check for Tiger copyfile(),
add CFLAGS to SHLIB_LD to support passing -isysroot in env(CFLAGS) to configure (flag can't be present twice, so can't be in both CFLAGS and LDFLAGS during configure), don't use -prebind when deploying on 10.4, define TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING (rdar://3171542). (SC_ENABLE_LANGINFO, SC_TIME_HANDLER): add/fix caching, fix obsolete autoconf macros. Sync with tk/unix/tcl.m4. * unix/configure.in: fix obsolete autoconf macros, sync gratuitous formatting/ordering differences with tk/unix/configure.in. * unix/Makefile.in: add CFLAGS to tclsh/tcltest link to make executable linking the same as during configure (needed to avoid loosing any linker relevant flags in CFLAGS, in particular flags that can't be in LDFLAGS). Avoid concurrent linking of tclsh and compiling of tclTestInit.o or xtTestInit.o during parallel make. (checkstubs, checkdoc, checkexports): dependency and Darwin fixes (dist): add new macosx files. * unix/tclLoadDyld.c (TclpDlopen): use NSADDIMAGE_OPTION_WITH_SEARCHING on second NSAddImage only. [Bug 1204237] (TclGuessPackageName): should not be MODULE_SCOPE. (TclpLoadMemory): ppc64 and endian (i386) fixes, add support for loading universal (fat) bundles from memory. * unix/tclUnixFCmd.c: * macosx/tclMacOSXFCmd.c: ppc64 and endian (i386) fixes. (TclMacOSXCopyFileAttributes): add support for new Tiger copyfile() API to enable copying of xattrs & ACLs by [file copy]. * generic/tcl.h: add Darwin specifc configure overrides for TCL_WIDE defines to support fat compiles of ppc and ppc64 at the same time, (replaces Darwin CVS fix by emoy, rdar://3693001). add/correct location of version numbers in macosx files. * generic/tclInt.h: clarify fat compile comment. * unix/tclUnixPort.h: add Darwin specifc configure overrides to support fat compiles, where configure runs only once for multiple architectures (replaces Darwin CVS fix by emoy, rdar://3693001). * macosx/tclMacOSXBundle.c: * macosx/tclMacOSXNotify.c: * unix/tclUnixNotfy.c: * unix/tclUnixPort.h: fix #include order to support compile time override of HAVE_COREFOUNDATION in tclUnixPort.h when building for ppc64 * macosx/Tcl.pbproj/default.pbxuser (new file): * macosx/Tcl.pbproj/jingham.pbxuser: * macosx/Tcl.pbproj/project.pbxproj: * macosx/Tcl.xcode/default.pbxuser (new file): * macosx/Tcl.xcode/project.pbxproj (new file): * macosx/Tcl.xcodeproj/default.pbxuser (new file): * macosx/Tcl.xcodeproj/project.pbxproj (new file): new/updated projects for Xcode 2.2 on 10.4, Xcode 1.5 on 10.3 & ProjectBuilder on 10.2, with native tcltest targets and support for universal (fat) compiles. * macosx/README: clarification/cleanup, document new Xcode projects and universal (fat) builds via CFLAGS (i.e. all of ppc ppc64 i386 at once). * unix/Makefile.in: * unix/aclocal.m4: * unix/configure.in: * unix/dltest/Makefile.in: * macosx/configure.ac (new file): add support for inclusion of unix/configure.in by macosx/configure.ac, allows generation of a config headers enabled configure script in macosx (required by Xcode projects). * macosx/GNUmakefile: rename from Makefile to avoid overwriting by configure run in tcl/macosx, add support for reusing configure cache, build target fixes, remove GENERIC_FLAGS override now handled by tcl.m4. * generic/tcl.decls: add Tcl_Main declaration as comment to avoid 'checkstubs' target complaining about it missing from stubs. * generic/regex.h: * generic/tclDate.c: * generic/tclEnv.c: * generic/tclGetDate.y: * generic/tclIOUtil.c: * generic/tclObj.c: * generic/tclStubInit.c: * generic/tclStubLib.c: * generic/tclPathObj.c: * generic/tclThreadAlloc.c: * generic/tclThreadStorage.c: * generic/tclTrace.c: * generic/tclVar.c: * generic/tommath.h: * tools/fix_tommath_h.tcl: * unix/tclUnixFCmd.c: ensure externally visible symbols not contained in stubs table are declared as MODULE_SCOPE (or as static if not used outside of own source file). These changes allow 'make checkstubs' to complete without error on Darwin with gcc 4. * generic/rege_dfa.c (getvacant): * generic/regexec.c (cfind): * generic/tclCompExpr.c (CompileSubExpr): * generic/tclNamesp.c (NamespaceEnsembleCmd): * unix/tclUnixChan.c (TclUnixWaitForFile): initialise variables to silence gcc 4 warnings. * generic/tclExecute.c (TclExecuteByteCode): fix unused variable warning when NO_WIDE_TYPE is defined. * generic/regguts.h: only #define NDEBUG if not already #defined. * unix/tclUnixNotfy.c: * macosx/tclMacOSXNotify.c: sync whitespace & comments. * unix/tclUnixPort.h: * win/tclWinPort.h: remove declaration of obsolete&unused TclpMutex API. * unix/configure: * unix/tclConfig.h.in: regen.
Diffstat (limited to 'macosx/tclMacOSXFCmd.c')
-rw-r--r--macosx/tclMacOSXFCmd.c120
1 files changed, 79 insertions, 41 deletions
diff --git a/macosx/tclMacOSXFCmd.c b/macosx/tclMacOSXFCmd.c
index aab5b44..17cccc2 100644
--- a/macosx/tclMacOSXFCmd.c
+++ b/macosx/tclMacOSXFCmd.c
@@ -5,11 +5,12 @@
* subcommands of the "file" command.
*
* Copyright (c) 2003 Tcl Core Team.
+ * Copyright (c) 2003-2005 Daniel A. Steffen <das@users.sourceforge.net>
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclMacOSXFCmd.c,v 1.5 2005/11/04 00:06:49 dkf Exp $
+ * RCS: @(#) $Id: tclMacOSXFCmd.c,v 1.6 2005/11/27 02:33:49 das Exp $
*/
#include "tclInt.h"
@@ -19,6 +20,20 @@
#include <sys/paths.h>
#endif
+/* Darwin 8 copyfile API */
+#ifdef HAVE_COPYFILE
+#ifdef HAVE_COPYFILE_H
+#include <copyfile.h>
+#else
+int copyfile(const char *from, const char *to, void *state, uint32_t flags);
+#define COPYFILE_ACL (1<<0)
+#define COPYFILE_XATTR (1<<2)
+#define COPYFILE_NOFOLLOW_SRC (1<<18)
+#endif
+#endif
+
+#include <libkern/OSByteOrder.h>
+
/*
* Constants for file attributes subcommand. Need to be kept in sync with
* tclUnixFCmd.c !
@@ -46,21 +61,23 @@ static int Tcl_GetOSTypeFromObj(Tcl_Interp *interp,
static Tcl_Obj * Tcl_NewOSTypeStringObj(CONST OSType newOSType);
enum {
- kFinfoIsInvisible = 0x4000,
+ kIsInvisible = 0x4000,
};
+#define kFinfoIsInvisible (OSSwapHostToBigConstInt16(kIsInvisible))
+
+typedef struct finderinfo {
+ u_int32_t type;
+ u_int32_t creator;
+ u_int16_t fdFlags;
+ u_int32_t location;
+ u_int16_t reserved;
+ u_int32_t extendedFileInfo[4];
+} __attribute__ ((__packed__)) finderinfo;
+
typedef struct fileinfobuf {
u_int32_t info_length;
- union {
- struct {
- u_int32_t type;
- u_int32_t creator;
- u_int16_t fdFlags;
- u_int16_t location;
- u_int32_t padding[4];
- } finder;
- off_t rsrcForkSize;
- } data __attribute__ ((packed));
+ u_int32_t data[8];
} fileinfobuf;
/*
@@ -93,6 +110,8 @@ TclMacOSXGetFileAttribute(
Tcl_StatBuf statBuf;
struct attrlist alist;
fileinfobuf finfo;
+ finderinfo *finder = (finderinfo*)(&finfo.data);
+ off_t *rsrcForkSize = (off_t*)(&finfo.data);
CONST char *native;
result = TclpObjStat(fileName, &statBuf);
@@ -114,7 +133,7 @@ TclMacOSXGetFileAttribute(
return TCL_ERROR;
}
- memset(&alist, 0, sizeof(struct attrlist));
+ bzero(&alist, sizeof(struct attrlist));
alist.bitmapcount = ATTR_BIT_MAP_COUNT;
if (objIndex == MACOSX_RSRCLENGTH_ATTRIBUTE) {
alist.fileattr = ATTR_FILE_RSRCLENGTH;
@@ -132,17 +151,19 @@ TclMacOSXGetFileAttribute(
switch (objIndex) {
case MACOSX_CREATOR_ATTRIBUTE:
- *attributePtrPtr = Tcl_NewOSTypeStringObj(finfo.data.finder.creator);
+ *attributePtrPtr = Tcl_NewOSTypeStringObj(
+ OSSwapBigToHostInt32(finder->creator));
break;
case MACOSX_TYPE_ATTRIBUTE:
- *attributePtrPtr = Tcl_NewOSTypeStringObj(finfo.data.finder.type);
+ *attributePtrPtr = Tcl_NewOSTypeStringObj(
+ OSSwapBigToHostInt32(finder->type));
break;
case MACOSX_HIDDEN_ATTRIBUTE:
*attributePtrPtr = Tcl_NewBooleanObj(
- (finfo.data.finder.fdFlags & kFinfoIsInvisible) != 0);
+ (finder->fdFlags & kFinfoIsInvisible) != 0);
break;
case MACOSX_RSRCLENGTH_ATTRIBUTE:
- *attributePtrPtr = Tcl_NewWideIntObj(finfo.data.rsrcForkSize);
+ *attributePtrPtr = Tcl_NewWideIntObj(*rsrcForkSize);
break;
}
return TCL_OK;
@@ -181,6 +202,8 @@ TclMacOSXSetFileAttribute(
Tcl_StatBuf statBuf;
struct attrlist alist;
fileinfobuf finfo;
+ finderinfo *finder = (finderinfo*)(&finfo.data);
+ off_t *rsrcForkSize = (off_t*)(&finfo.data);
CONST char *native;
result = TclpObjStat(fileName, &statBuf);
@@ -202,7 +225,7 @@ TclMacOSXSetFileAttribute(
return TCL_ERROR;
}
- memset(&alist, 0, sizeof(struct attrlist));
+ bzero(&alist, sizeof(struct attrlist));
alist.bitmapcount = ATTR_BIT_MAP_COUNT;
if (objIndex == MACOSX_RSRCLENGTH_ATTRIBUTE) {
alist.fileattr = ATTR_FILE_RSRCLENGTH;
@@ -219,33 +242,33 @@ TclMacOSXSetFileAttribute(
}
if (objIndex != MACOSX_RSRCLENGTH_ATTRIBUTE) {
+ OSType t;
+ int h;
+
switch (objIndex) {
case MACOSX_CREATOR_ATTRIBUTE:
- if (Tcl_GetOSTypeFromObj(interp, attributePtr,
- &finfo.data.finder.creator) != TCL_OK) {
+ if (Tcl_GetOSTypeFromObj(interp, attributePtr, &t) != TCL_OK) {
return TCL_ERROR;
}
+ finder->creator = OSSwapHostToBigInt32(t);
break;
case MACOSX_TYPE_ATTRIBUTE:
- if (Tcl_GetOSTypeFromObj(interp, attributePtr,
- &finfo.data.finder.type) != TCL_OK) {
+ if (Tcl_GetOSTypeFromObj(interp, attributePtr, &t) != TCL_OK) {
return TCL_ERROR;
}
+ finder->type = OSSwapHostToBigInt32(t);
break;
- case MACOSX_HIDDEN_ATTRIBUTE: {
- int hidden;
-
- if (Tcl_GetBooleanFromObj(interp,attributePtr,&hidden) != TCL_OK) {
+ case MACOSX_HIDDEN_ATTRIBUTE:
+ if (Tcl_GetBooleanFromObj(interp, attributePtr, &h) != TCL_OK) {
return TCL_ERROR;
}
- if (hidden) {
- finfo.data.finder.fdFlags |= kFinfoIsInvisible;
+ if (h) {
+ finder->fdFlags |= kFinfoIsInvisible;
} else {
- finfo.data.finder.fdFlags &= ~kFinfoIsInvisible;
+ finder->fdFlags &= ~kFinfoIsInvisible;
}
break;
}
- }
result = setattrlist(native, &alist,
&finfo.data, sizeof(finfo.data), 0);
@@ -257,14 +280,14 @@ TclMacOSXSetFileAttribute(
return TCL_ERROR;
}
} else {
- off_t newRsrcForkSize;
+ Tcl_WideInt newRsrcForkSize;
if (Tcl_GetWideIntFromObj(interp, attributePtr,
&newRsrcForkSize) != TCL_OK) {
return TCL_ERROR;
}
- if (newRsrcForkSize != finfo.data.rsrcForkSize) {
+ if (newRsrcForkSize != *rsrcForkSize) {
Tcl_DString ds;
/*
@@ -331,11 +354,19 @@ TclMacOSXCopyFileAttributes(
CONST Tcl_StatBuf *statBufPtr)
/* Stat info for source file */
{
-#ifdef HAVE_GETATTRLIST
+#if defined(HAVE_COPYFILE)
+ if (copyfile(src, dst, NULL, COPYFILE_XATTR |
+ (S_ISLNK(statBufPtr->st_mode) ? COPYFILE_NOFOLLOW_SRC :
+ COPYFILE_ACL)) < 0) {
+ return TCL_ERROR;
+ }
+ return TCL_OK;
+#elif defined(HAVE_GETATTRLIST)
struct attrlist alist;
fileinfobuf finfo;
+ off_t *rsrcForkSize = (off_t*)(&finfo.data);
- memset(&alist, 0, sizeof(struct attrlist));
+ bzero(&alist, sizeof(struct attrlist));
alist.bitmapcount = ATTR_BIT_MAP_COUNT;
alist.commonattr = ATTR_CMN_FNDRINFO;
@@ -359,7 +390,7 @@ TclMacOSXCopyFileAttributes(
return TCL_ERROR;
}
- if(finfo.data.rsrcForkSize > 0) {
+ if(*rsrcForkSize > 0) {
int result;
Tcl_DString ds_src, ds_dst;
@@ -422,14 +453,18 @@ Tcl_GetOSTypeFromObj(
string = Tcl_GetStringFromObj(objPtr, &length);
Tcl_UtfToExternalDString(encoding, string, length, &ds);
- if (Tcl_DStringLength(&ds) > sizeof(OSType)) {
+ if (Tcl_DStringLength(&ds) > 4) {
Tcl_AppendResult(interp, "expected Macintosh OS type but got \"",
string, "\": ", NULL);
result = TCL_ERROR;
} else {
- memset(osTypePtr, 0, sizeof(OSType));
- memcpy(osTypePtr, Tcl_DStringValue(&ds),
+ char string[4] = {'\0','\0','\0','\0'};
+ memcpy(string, Tcl_DStringValue(&ds),
(size_t) Tcl_DStringLength(&ds));
+ *osTypePtr = (OSType) string[0] << 24 |
+ (OSType) string[1] << 16 |
+ (OSType) string[2] << 8 |
+ (OSType) string[3];
}
Tcl_DStringFree(&ds);
Tcl_FreeEncoding(encoding);
@@ -456,13 +491,16 @@ static Tcl_Obj *
Tcl_NewOSTypeStringObj(
CONST OSType newOSType) /* OSType used to initialize the new object. */
{
- char string[sizeof(OSType)+1];
+ char string[5];
Tcl_Obj *resultPtr;
Tcl_DString ds;
Tcl_Encoding encoding = Tcl_GetEncoding(NULL, "macRoman");
- memcpy(string, &newOSType, sizeof(OSType));
- string[sizeof(OSType)] = '\0';
+ string[0] = (char) (newOSType >> 24);
+ string[1] = (char) (newOSType >> 16);
+ string[2] = (char) (newOSType >> 8);
+ string[3] = (char) (newOSType);
+ string[4] = '\0';
Tcl_ExternalToUtfDString(encoding, string, -1, &ds);
resultPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds),
Tcl_DStringLength(&ds));