diff options
Diffstat (limited to 'Mac/Modules/file/_Filemodule.c')
-rw-r--r-- | Mac/Modules/file/_Filemodule.c | 366 |
1 files changed, 163 insertions, 203 deletions
diff --git a/Mac/Modules/file/_Filemodule.c b/Mac/Modules/file/_Filemodule.c index c1b4310..c3d1abf 100644 --- a/Mac/Modules/file/_Filemodule.c +++ b/Mac/Modules/file/_Filemodule.c @@ -50,13 +50,13 @@ static int Alias_Convert(PyObject *v, AliasHandle *p_itself); static int UTCDateTime_Convert(PyObject *v, UTCDateTime *ptr) { - return PyArg_Parse(v, "(HlH)", &ptr->highSeconds, &ptr->lowSeconds, &ptr->fraction); + return PyArg_Parse(v, "(HlH)", &ptr->highSeconds, &ptr->lowSeconds, &ptr->fraction); } static PyObject * UTCDateTime_New(UTCDateTime *ptr) { - return Py_BuildValue("(HlH)", ptr->highSeconds, ptr->lowSeconds, ptr->fraction); + return Py_BuildValue("(HlH)", ptr->highSeconds, ptr->lowSeconds, ptr->fraction); } /* @@ -65,21 +65,21 @@ UTCDateTime_New(UTCDateTime *ptr) static int myPyMac_GetOptFSSpecPtr(PyObject *v, FSSpec **spec) { - if (v == Py_None) { - *spec = NULL; - return 1; - } - return PyMac_GetFSSpec(v, *spec); + if (v == Py_None) { + *spec = NULL; + return 1; + } + return PyMac_GetFSSpec(v, *spec); } static int myPyMac_GetOptFSRefPtr(PyObject *v, FSRef **ref) { - if (v == Py_None) { - *ref = NULL; - return 1; - } - return PyMac_GetFSRef(v, *ref); + if (v == Py_None) { + *ref = NULL; + return 1; + } + return PyMac_GetFSRef(v, *ref); } /* @@ -89,7 +89,7 @@ static PyObject * PyMac_BuildHFSUniStr255(HFSUniStr255 *itself) { - return Py_BuildValue("u#", itself->unicode, itself->length); + return Py_BuildValue("u#", itself->unicode, itself->length); } static PyObject *File_Error; @@ -114,6 +114,7 @@ static PyObject *FSCatalogInfo_New(FSCatalogInfo *itself) it->ob_itself = *itself; return (PyObject *)it; } + static int FSCatalogInfo_Convert(PyObject *v, FSCatalogInfo *p_itself) { if (!FSCatalogInfo_Check(v)) @@ -349,43 +350,43 @@ static PyGetSetDef FSCatalogInfo_getsetlist[] = { #define FSCatalogInfo_repr NULL #define FSCatalogInfo_hash NULL -static int FSCatalogInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds) +static int FSCatalogInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds) { static char *kw[] = { - "nodeFlags", - "volume", - "parentDirID", - "nodeID", - "createDate", - "contentModDate", - "atributeModDate", - "accessDate", - "backupDate", - "valence", - "dataLogicalSize", - "dataPhysicalSize", - "rsrcLogicalSize", - "rsrcPhysicalSize", - "sharingFlags", - "userPrivileges" - , 0}; - - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|HhllO&O&O&O&O&llllllb", kw, &((FSCatalogInfoObject *)self)->ob_itself.nodeFlags, - &((FSCatalogInfoObject *)self)->ob_itself.volume, - &((FSCatalogInfoObject *)self)->ob_itself.parentDirID, - &((FSCatalogInfoObject *)self)->ob_itself.nodeID, - UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.createDate, - UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.contentModDate, - UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.attributeModDate, - UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.accessDate, - UTCDateTime_Convert, &((FSCatalogInfoObject *)self)->ob_itself.backupDate, - &((FSCatalogInfoObject *)self)->ob_itself.valence, - &((FSCatalogInfoObject *)self)->ob_itself.dataLogicalSize, - &((FSCatalogInfoObject *)self)->ob_itself.dataPhysicalSize, - &((FSCatalogInfoObject *)self)->ob_itself.rsrcLogicalSize, - &((FSCatalogInfoObject *)self)->ob_itself.rsrcPhysicalSize, - &((FSCatalogInfoObject *)self)->ob_itself.sharingFlags, - &((FSCatalogInfoObject *)self)->ob_itself.userPrivileges)) + "nodeFlags", + "volume", + "parentDirID", + "nodeID", + "createDate", + "contentModDate", + "atributeModDate", + "accessDate", + "backupDate", + "valence", + "dataLogicalSize", + "dataPhysicalSize", + "rsrcLogicalSize", + "rsrcPhysicalSize", + "sharingFlags", + "userPrivileges" + , 0}; + + if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|HhllO&O&O&O&O&llllllb", kw, &((FSCatalogInfoObject *)_self)->ob_itself.nodeFlags, + &((FSCatalogInfoObject *)_self)->ob_itself.volume, + &((FSCatalogInfoObject *)_self)->ob_itself.parentDirID, + &((FSCatalogInfoObject *)_self)->ob_itself.nodeID, + UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.createDate, + UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.contentModDate, + UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.attributeModDate, + UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.accessDate, + UTCDateTime_Convert, &((FSCatalogInfoObject *)_self)->ob_itself.backupDate, + &((FSCatalogInfoObject *)_self)->ob_itself.valence, + &((FSCatalogInfoObject *)_self)->ob_itself.dataLogicalSize, + &((FSCatalogInfoObject *)_self)->ob_itself.dataPhysicalSize, + &((FSCatalogInfoObject *)_self)->ob_itself.rsrcLogicalSize, + &((FSCatalogInfoObject *)_self)->ob_itself.rsrcPhysicalSize, + &((FSCatalogInfoObject *)_self)->ob_itself.sharingFlags, + &((FSCatalogInfoObject *)_self)->ob_itself.userPrivileges)) { return -1; } @@ -394,7 +395,7 @@ static int FSCatalogInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds) #define FSCatalogInfo_tp_alloc PyType_GenericAlloc -static PyObject *FSCatalogInfo_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static PyObject *FSCatalogInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) { PyObject *self; @@ -473,6 +474,7 @@ static PyObject *FInfo_New(FInfo *itself) it->ob_itself = *itself; return (PyObject *)it; } + static int FInfo_Convert(PyObject *v, FInfo *p_itself) { if (!FInfo_Check(v)) @@ -564,14 +566,14 @@ static PyGetSetDef FInfo_getsetlist[] = { #define FInfo_repr NULL #define FInfo_hash NULL -static int FInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds) +static int FInfo_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds) { FInfo *itself = NULL; static char *kw[] = {"itself", 0}; - if (PyArg_ParseTupleAndKeywords(args, kwds, "|O&", kw, FInfo_Convert, &itself)) + if (PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&", kw, FInfo_Convert, &itself)) { - if (itself) memcpy(&((FInfoObject *)self)->ob_itself, itself, sizeof(FInfo)); + if (itself) memcpy(&((FInfoObject *)_self)->ob_itself, itself, sizeof(FInfo)); return 0; } return -1; @@ -579,7 +581,7 @@ static int FInfo_tp_init(PyObject *self, PyObject *args, PyObject *kwds) #define FInfo_tp_alloc PyType_GenericAlloc -static PyObject *FInfo_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static PyObject *FInfo_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) { PyObject *self; @@ -660,6 +662,7 @@ static PyObject *Alias_New(AliasHandle itself) it->ob_freeit = NULL; return (PyObject *)it; } + static int Alias_Convert(PyObject *v, AliasHandle *p_itself) { if (!Alias_Check(v)) @@ -863,14 +866,14 @@ static PyMethodDef Alias_methods[] = { static PyObject *Alias_get_data(AliasObject *self, void *closure) { int size; - PyObject *rv; - - size = GetHandleSize((Handle)self->ob_itself); - HLock((Handle)self->ob_itself); - rv = PyString_FromStringAndSize(*(Handle)self->ob_itself, size); - HUnlock((Handle)self->ob_itself); - return rv; - + PyObject *rv; + + size = GetHandleSize((Handle)self->ob_itself); + HLock((Handle)self->ob_itself); + rv = PyString_FromStringAndSize(*(Handle)self->ob_itself, size); + HUnlock((Handle)self->ob_itself); + return rv; + } #define Alias_set_data NULL @@ -886,7 +889,7 @@ static PyGetSetDef Alias_getsetlist[] = { #define Alias_repr NULL #define Alias_hash NULL -static int Alias_tp_init(PyObject *self, PyObject *args, PyObject *kwds) +static int Alias_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds) { AliasHandle itself = NULL; char *rawdata = NULL; @@ -894,7 +897,7 @@ static int Alias_tp_init(PyObject *self, PyObject *args, PyObject *kwds) Handle h; static char *kw[] = {"itself", "rawdata", 0}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O&s#", kw, Alias_Convert, &itself, &rawdata, &rawdatalen)) + if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|O&s#", kw, Alias_Convert, &itself, &rawdata, &rawdatalen)) return -1; if (itself && rawdata) { @@ -916,16 +919,16 @@ static int Alias_tp_init(PyObject *self, PyObject *args, PyObject *kwds) HLock(h); memcpy((char *)*h, rawdata, rawdatalen); HUnlock(h); - ((AliasObject *)self)->ob_itself = (AliasHandle)h; + ((AliasObject *)_self)->ob_itself = (AliasHandle)h; return 0; } - ((AliasObject *)self)->ob_itself = itself; + ((AliasObject *)_self)->ob_itself = itself; return 0; } #define Alias_tp_alloc PyType_GenericAlloc -static PyObject *Alias_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static PyObject *Alias_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) { PyObject *self; @@ -1253,49 +1256,6 @@ static PyObject *FSSpec_IsAliasFile(FSSpecObject *_self, PyObject *_args) return _res; } -static OSErr -_PyMac_GetFullPathname(FSSpec *fss, char *path, int len) -{ - FSRef fsr; - OSErr err; - - *path = '\0'; - err = FSpMakeFSRef(fss, &fsr); - if (err == fnfErr) { - /* FSSpecs can point to non-existing files, fsrefs can't. */ - FSSpec fss2; - int tocopy; - - err = FSMakeFSSpec(fss->vRefNum, fss->parID, "", &fss2); - if (err) - return err; - err = FSpMakeFSRef(&fss2, &fsr); - if (err) - return err; - err = (OSErr)FSRefMakePath(&fsr, path, len-1); - if (err) - return err; - /* This part is not 100% safe: we append the filename part, but - ** I'm not sure that we don't run afoul of the various 8bit - ** encodings here. Will have to look this up at some point... - */ - strcat(path, "/"); - tocopy = fss->name[0]; - if ((strlen(path) + tocopy) >= len) - tocopy = len - strlen(path) - 1; - if (tocopy > 0) - strncat(path, fss->name+1, tocopy); - } - else { - if (err) - return err; - err = (OSErr)FSRefMakePath(&fsr, path, len); - if (err) - return err; - } - return 0; -} - static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args) { PyObject *_res = NULL; @@ -1304,11 +1264,11 @@ static PyObject *FSSpec_as_pathname(FSSpecObject *_self, PyObject *_args) OSErr err; if (!PyArg_ParseTuple(_args, "")) - return NULL; - err = _PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf)); + return NULL; + err = PyMac_GetFullPathname(&_self->ob_itself, strbuf, sizeof(strbuf)); if ( err ) { - PyMac_Error(err); - return NULL; + PyMac_Error(err); + return NULL; } _res = PyString_FromString(strbuf); return _res; @@ -1320,9 +1280,9 @@ static PyObject *FSSpec_as_tuple(FSSpecObject *_self, PyObject *_args) PyObject *_res = NULL; if (!PyArg_ParseTuple(_args, "")) - return NULL; - _res = Py_BuildValue("(iis#)", _self->ob_itself.vRefNum, _self->ob_itself.parID, - &_self->ob_itself.name[1], _self->ob_itself.name[0]); + return NULL; + _res = Py_BuildValue("(iis#)", _self->ob_itself.vRefNum, _self->ob_itself.parID, + &_self->ob_itself.name[1], _self->ob_itself.name[0]); return _res; } @@ -1384,22 +1344,22 @@ static PyObject * FSSpec_repr(FSSpecObject *self) { char buf[512]; PyOS_snprintf(buf, sizeof(buf), "%s((%d, %ld, '%.*s'))", - self->ob_type->tp_name, - self->ob_itself.vRefNum, - self->ob_itself.parID, - self->ob_itself.name[0], self->ob_itself.name+1); + self->ob_type->tp_name, + self->ob_itself.vRefNum, + self->ob_itself.parID, + self->ob_itself.name[0], self->ob_itself.name+1); return PyString_FromString(buf); } #define FSSpec_hash NULL -static int FSSpec_tp_init(PyObject *self, PyObject *args, PyObject *kwds) +static int FSSpec_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds) { PyObject *v = NULL; char *rawdata = NULL; int rawdatalen = 0; static char *kw[] = {"itself", "rawdata", 0}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Os#", kw, &v, &rawdata, &rawdatalen)) + if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|Os#", kw, &v, &rawdata, &rawdatalen)) return -1; if (v && rawdata) { @@ -1418,16 +1378,16 @@ static int FSSpec_tp_init(PyObject *self, PyObject *args, PyObject *kwds) PyErr_SetString(PyExc_TypeError, "FSSpec rawdata incorrect size"); return -1; } - memcpy(&((FSSpecObject *)self)->ob_itself, rawdata, rawdatalen); + memcpy(&((FSSpecObject *)_self)->ob_itself, rawdata, rawdatalen); return 0; } - if (PyMac_GetFSSpec(v, &((FSSpecObject *)self)->ob_itself)) return 0; + if (PyMac_GetFSSpec(v, &((FSSpecObject *)_self)->ob_itself)) return 0; return -1; } #define FSSpec_tp_alloc PyType_GenericAlloc -static PyObject *FSSpec_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static PyObject *FSSpec_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) { PyObject *self; @@ -1857,10 +1817,10 @@ static PyObject *FSRef_FSRefMakePath(FSRefObject *_self, PyObject *_args) UInt32 maxPathSize = MAXPATHNAME; if (!PyArg_ParseTuple(_args, "")) - return NULL; + return NULL; _err = FSRefMakePath(&_self->ob_itself, - path, - maxPathSize); + path, + maxPathSize); if (_err != noErr) return PyMac_Error(_err); _res = Py_BuildValue("s", path); return _res; @@ -1872,7 +1832,7 @@ static PyObject *FSRef_as_pathname(FSRefObject *_self, PyObject *_args) PyObject *_res = NULL; if (!PyArg_ParseTuple(_args, "")) - return NULL; + return NULL; _res = FSRef_FSRefMakePath(_self, _args); return _res; @@ -1936,14 +1896,14 @@ static PyGetSetDef FSRef_getsetlist[] = { #define FSRef_repr NULL #define FSRef_hash NULL -static int FSRef_tp_init(PyObject *self, PyObject *args, PyObject *kwds) +static int FSRef_tp_init(PyObject *_self, PyObject *_args, PyObject *_kwds) { PyObject *v = NULL; char *rawdata = NULL; int rawdatalen = 0; static char *kw[] = {"itself", "rawdata", 0}; - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Os#", kw, &v, &rawdata, &rawdatalen)) + if (!PyArg_ParseTupleAndKeywords(_args, _kwds, "|Os#", kw, &v, &rawdata, &rawdatalen)) return -1; if (v && rawdata) { @@ -1962,16 +1922,16 @@ static int FSRef_tp_init(PyObject *self, PyObject *args, PyObject *kwds) PyErr_SetString(PyExc_TypeError, "FSRef rawdata incorrect size"); return -1; } - memcpy(&((FSRefObject *)self)->ob_itself, rawdata, rawdatalen); + memcpy(&((FSRefObject *)_self)->ob_itself, rawdata, rawdatalen); return 0; } - if (PyMac_GetFSRef(v, &((FSRefObject *)self)->ob_itself)) return 0; + if (PyMac_GetFSRef(v, &((FSRefObject *)_self)->ob_itself)) return 0; return -1; } #define FSRef_tp_alloc PyType_GenericAlloc -static PyObject *FSRef_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +static PyObject *FSRef_tp_new(PyTypeObject *type, PyObject *_args, PyObject *_kwds) { PyObject *self; @@ -3032,13 +2992,13 @@ static PyObject *File_pathname(PyObject *_self, PyObject *_args) PyObject *obj; if (!PyArg_ParseTuple(_args, "O", &obj)) - return NULL; + return NULL; if (PyString_Check(obj)) { - Py_INCREF(obj); - return obj; + Py_INCREF(obj); + return obj; } if (PyUnicode_Check(obj)) - return PyUnicode_AsEncodedString(obj, "utf8", "strict"); + return PyUnicode_AsEncodedString(obj, "utf8", "strict"); _res = PyObject_CallMethod(obj, "as_pathname", NULL); return _res; @@ -3149,86 +3109,86 @@ static PyMethodDef File_methods[] = { int PyMac_GetFSSpec(PyObject *v, FSSpec *spec) { - Str255 path; - short refnum; - long parid; - OSErr err; - FSRef fsr; - - if (FSSpec_Check(v)) { - *spec = ((FSSpecObject *)v)->ob_itself; - return 1; - } - - if (PyArg_Parse(v, "(hlO&)", - &refnum, &parid, PyMac_GetStr255, &path)) { - err = FSMakeFSSpec(refnum, parid, path, spec); - if ( err && err != fnfErr ) { - PyMac_Error(err); - return 0; - } - return 1; - } - PyErr_Clear(); - /* Otherwise we try to go via an FSRef. On OSX we go all the way, - ** on OS9 we accept only a real FSRef object - */ - if ( PyMac_GetFSRef(v, &fsr) ) { - err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL); - if (err != noErr) { - PyMac_Error(err); - return 0; - } - return 1; - } - return 0; + Str255 path; + short refnum; + long parid; + OSErr err; + FSRef fsr; + + if (FSSpec_Check(v)) { + *spec = ((FSSpecObject *)v)->ob_itself; + return 1; + } + + if (PyArg_Parse(v, "(hlO&)", + &refnum, &parid, PyMac_GetStr255, &path)) { + err = FSMakeFSSpec(refnum, parid, path, spec); + if ( err && err != fnfErr ) { + PyMac_Error(err); + return 0; + } + return 1; + } + PyErr_Clear(); + /* Otherwise we try to go via an FSRef. On OSX we go all the way, + ** on OS9 we accept only a real FSRef object + */ + if ( PyMac_GetFSRef(v, &fsr) ) { + err = FSGetCatalogInfo(&fsr, kFSCatInfoNone, NULL, NULL, spec, NULL); + if (err != noErr) { + PyMac_Error(err); + return 0; + } + return 1; + } + return 0; } int PyMac_GetFSRef(PyObject *v, FSRef *fsr) { - OSStatus err; - FSSpec fss; - - if (FSRef_Check(v)) { - *fsr = ((FSRefObject *)v)->ob_itself; - return 1; - } - - /* On OSX we now try a pathname */ - if ( PyString_Check(v) || PyUnicode_Check(v)) { - char *path = NULL; - if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path)) - return NULL; - if ( (err=FSPathMakeRef(path, fsr, NULL)) ) { - PyMac_Error(err); - return 0; - } - return 1; - } - /* XXXX Should try unicode here too */ - /* Otherwise we try to go via an FSSpec */ - if (FSSpec_Check(v)) { - fss = ((FSSpecObject *)v)->ob_itself; - if ((err=FSpMakeFSRef(&fss, fsr)) == 0) - return 1; - PyMac_Error(err); - return 0; - } - PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required"); - return 0; + OSStatus err; + FSSpec fss; + + if (FSRef_Check(v)) { + *fsr = ((FSRefObject *)v)->ob_itself; + return 1; + } + + /* On OSX we now try a pathname */ + if ( PyString_Check(v) || PyUnicode_Check(v)) { + char *path = NULL; + if (!PyArg_Parse(v, "et", Py_FileSystemDefaultEncoding, &path)) + return 0; + if ( (err=FSPathMakeRef(path, fsr, NULL)) ) { + PyMac_Error(err); + return 0; + } + return 1; + } + /* XXXX Should try unicode here too */ + /* Otherwise we try to go via an FSSpec */ + if (FSSpec_Check(v)) { + fss = ((FSSpecObject *)v)->ob_itself; + if ((err=FSpMakeFSRef(&fss, fsr)) == 0) + return 1; + PyMac_Error(err); + return 0; + } + PyErr_SetString(PyExc_TypeError, "FSRef, FSSpec or pathname required"); + return 0; } extern PyObject * PyMac_BuildFSSpec(FSSpec *spec) { - return FSSpec_New(spec); + return FSSpec_New(spec); } extern PyObject * PyMac_BuildFSRef(FSRef *spec) { - return FSRef_New(spec); + return FSRef_New(spec); } |