77
82
if (!PyArg_ParseTuple(args, "l", &n))
80
v = PyString_FromStringAndSize((char *)NULL, n);
85
v = PyBytes_FromStringAndSize((char *)NULL, n);
84
err = FSRead(self->fRefNum, &n, PyString_AsString(v));
89
err = FSReadFork(self->fRefNum, fsAtMark, 0, n, PyString_AsString(v), &n2);
85
90
if (err && err != eofErr) {
90
_PyString_Resize(&v, n);
95
_PyString_Resize(&v, n2);
110
115
if (!PyArg_ParseTuple(args, "s#", &buffer, &size))
112
err = FSWrite(self->fRefNum, &size, buffer);
117
err = FSWriteFork(self->fRefNum, fsAtMark, 0, size, buffer, NULL);
114
119
PyMac_Error(err);
126
131
static PyObject *
127
132
rf_seek(rfobject *self, PyObject *args)
130
135
int whence = SEEK_SET;
134
139
if (self->isclosed) {
135
140
PyErr_SetString(PyExc_ValueError, "Operation on closed file");
138
if (!PyArg_ParseTuple(args, "l|i", &amount, &whence))
143
if (!PyArg_ParseTuple(args, "l|i", &amount, &whence)) {
141
if ((err = GetEOF(self->fRefNum, &eof)))
144
147
switch (whence) {
146
if ((err = GetFPos(self->fRefNum, &pos)))
156
158
PyErr_BadArgument();
162
/* Don't bother implementing seek past EOF */
163
if (pos > eof || pos < 0) {
168
if ((err = SetFPos(self->fRefNum, fsFromStart, pos)) ) {
162
err = FSSetForkPosition(self->fRefNum, mode, amount);
170
164
PyMac_Error(err);
192
186
if (!PyArg_ParseTuple(args, ""))
194
if ((err = GetFPos(self->fRefNum, &where)) ) {
189
err = FSGetForkPosition(self->fRefNum, &where);
195
191
PyMac_Error(err);
198
return PyInt_FromLong(where);
194
return PyLong_FromLongLong(where);
201
197
static char rf_close__doc__[] =
292
289
static PyObject *
293
290
MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
297
292
PyObject *creator, *type, *res;
300
if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
302
if ((err = FSpGetFInfo(&fss, &info)) != noErr)
303
return PyErr_Mac(MacOS_Error, err);
304
creator = PyString_FromStringAndSize((char *)&info.fdCreator, 4);
305
type = PyString_FromStringAndSize((char *)&info.fdType, 4);
295
FSCatalogInfo cataloginfo;
298
if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &ref)) {
300
/* This function is documented to take an FSSpec as well,
301
* which only works in 32-bit mode.
307
if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss))
310
if ((err = FSpGetFInfo(&fss, &info)) != noErr) {
311
return PyErr_Mac(MacOS_Error, err);
313
creator = PyString_FromStringAndSize(
314
(char *)&info.fdCreator, 4);
315
type = PyString_FromStringAndSize((char *)&info.fdType, 4);
316
res = Py_BuildValue("OO", creator, type);
322
#endif /* __LP64__ */
325
err = FSGetCatalogInfo(&ref,
326
kFSCatInfoFinderInfo|kFSCatInfoNodeFlags, &cataloginfo,
329
PyErr_Mac(MacOS_Error, err);
333
if ((cataloginfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) {
334
/* Directory: doesn't have type/creator info.
336
* The specific error code is for backward compatibility with
339
PyErr_Mac(MacOS_Error, fnfErr);
343
finfo = (FileInfo*)&(cataloginfo.finderInfo);
344
creator = PyString_FromStringAndSize((char*)&(finfo->fileCreator), 4);
345
type = PyString_FromStringAndSize((char*)&(finfo->fileType), 4);
306
347
res = Py_BuildValue("OO", creator, type);
307
348
Py_DECREF(creator);
314
355
static PyObject *
315
356
MacOS_SetCreatorAndType(PyObject *self, PyObject *args)
318
358
ResType creator, type;
362
FSCatalogInfo cataloginfo;
322
364
if (!PyArg_ParseTuple(args, "O&O&O&",
365
PyMac_GetFSRef, &ref, PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) {
367
/* Try to handle FSSpec arguments, for backward compatibility */
371
if (!PyArg_ParseTuple(args, "O&O&O&",
323
372
PyMac_GetFSSpec, &fss, PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
325
if ((err = FSpGetFInfo(&fss, &info)) != noErr)
326
return PyErr_Mac(MacOS_Error, err);
327
info.fdCreator = creator;
329
if ((err = FSpSetFInfo(&fss, &info)) != noErr)
330
return PyErr_Mac(MacOS_Error, err);
375
if ((err = FSpGetFInfo(&fss, &info)) != noErr)
376
return PyErr_Mac(MacOS_Error, err);
378
info.fdCreator = creator;
381
if ((err = FSpSetFInfo(&fss, &info)) != noErr)
382
return PyErr_Mac(MacOS_Error, err);
387
#endif /* __LP64__ */
390
err = FSGetCatalogInfo(&ref,
391
kFSCatInfoFinderInfo|kFSCatInfoNodeFlags, &cataloginfo,
394
PyErr_Mac(MacOS_Error, err);
398
if ((cataloginfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) {
399
/* Directory: doesn't have type/creator info.
401
* The specific error code is for backward compatibility with
404
PyErr_Mac(MacOS_Error, fnfErr);
408
finfo = (FileInfo*)&(cataloginfo.finderInfo);
409
finfo->fileCreator = creator;
410
finfo->fileType = type;
412
err = FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &cataloginfo);
414
PyErr_Mac(MacOS_Error, fnfErr);
331
418
Py_INCREF(Py_None);
532
626
char *mode = "r";
534
SignedByte permission = 1;
628
SInt8 permission = fsRdPerm;
537
if (!PyArg_ParseTuple(args, "O&|s", PyMac_GetFSSpec, &fss, &mode))
632
if (!PyArg_ParseTuple(args, "O&|s", PyMac_GetFSRef, &ref, &mode))
540
635
switch (*mode++) {
542
case 'r': permission = 1; break;
543
case 'w': permission = 2; break;
637
case 'r': permission = fsRdPerm; break;
638
case 'w': permission = fsWrPerm; break;
546
641
PyErr_BadArgument();
646
err = FSGetResourceForkName(&name);
551
652
if ( (fp = newrfobject()) == NULL )
554
err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
556
if ( err == fnfErr ) {
557
/* In stead of doing complicated things here to get creator/type
558
** correct we let the standard i/o library handle it
561
char pathname[PATHNAMELEN];
563
if ( (err=PyMac_GetFullPathname(&fss, pathname, PATHNAMELEN)) ) {
569
if ( (tfp = fopen(pathname, "w")) == NULL ) {
570
PyMac_Error(fnfErr); /* What else... */
575
err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
656
err = FSOpenFork(&ref, name.length, name.unicode, permission, &fp->fRefNum);
579
659
PyMac_Error(err);
587
668
static PyMethodDef MacOS_Methods[] = {
588
669
{"GetCreatorAndType", MacOS_GetCreatorAndType, 1, getcrtp_doc},
589
670
{"SetCreatorAndType", MacOS_SetCreatorAndType, 1, setcrtp_doc},
590
671
{"GetErrorString", MacOS_GetErrorString, 1, geterr_doc},
591
672
{"openrf", MacOS_openrf, 1, openrf_doc},
592
674
{"splash", MacOS_splash, 1, splash_doc},
593
675
{"DebugStr", MacOS_DebugStr, 1, DebugStr_doc},
676
{"SysBeep", MacOS_SysBeep, 1, SysBeep_doc},
677
#endif /* __LP64__ */
594
678
{"GetTicks", MacOS_GetTicks, 1, GetTicks_doc},
595
{"SysBeep", MacOS_SysBeep, 1, SysBeep_doc},
596
679
{"WMAvailable", MacOS_WMAvailable, 1, WMAvailable_doc},
597
680
{NULL, NULL} /* Sentinel */