/***************************************************************************** * * FileLengthEx() * *****************************************************************************/ NLM_EXTERN Nlm_Int8 LIBCALL Nlm_FileLengthEx(const Nlm_Char* fileName) { if (!fileName || !*fileName) return -1; #ifdef OS_MAC {{ OSErr err; HParamBlockRec params; Nlm_Char path[256]; Nlm_MemSet ((Nlm_VoidPtr) ¶ms, 0, sizeof (HParamBlockRec)); Nlm_StringNCpy_0(path, fileName, sizeof(path)); Nlm_CtoPstr((Nlm_CharPtr) path); params.fileParam.ioNamePtr = (StringPtr)path; params.fileParam.ioVRefNum = 0; params.fileParam.ioFDirIndex = 0; err = PBHGetFInfo(¶ms, FALSE); return (err == noErr) ? params.fileParam.ioFlLgLen : -1; }} #else {{ struct stat sbuf; return (stat(fileName, &sbuf) == 0) ? sbuf.st_size : -1; }} #endif }
void mac_cleanup_tmpf(void) { int i,err; HFileParam pb; char fname[256]; for (i = 0; i < MAXTMPF; ++i) if (tmpf[i].flags) { strcpy(fname,tmpf[i].path); pb.ioCompletion=nil; c2pstr(fname); pb.ioNamePtr=(uchar *)fname; pb.ioVRefNum=0; pb.ioFDirIndex=0; pb.ioFRefNum=0; pb.ioDirID=0; err=PBHGetFInfo((HParmBlkPtr)&pb,false); if (pb.ioFRefNum!=0){ strcpy(fname,tmpf[i].path); pb.ioCompletion=nil; c2pstr(fname); pb.ioNamePtr=(uchar *)fname; pb.ioVRefNum=0; pb.ioDirID=0; err=PBClose((ParmBlkPtr)&pb,false); } rmtemp(tmpf[i].path); } } /* mac_cleanup_tmpf */
const char *autotype_via_mactype(const char *file) { OSErr err; CInfoPBRec CPB; HFileParam hfp; char *d, kind[10], buf[MAXPATHLEN]; short vRef = 0; long dirID = 0; if (!file) return nil; strcpy(buf, file); /* thou shalt not poke thy caller's buffer */ err = GetPathRef(buf, &vRef, &dirID); /* GetPathRef does c2p */ c2pstr(buf); CPB.hFileInfo.ioNamePtr = buf; CPB.hFileInfo.ioDirID = 0; CPB.hFileInfo.ioVRefNum = 0; CPB.hFileInfo.ioFDirIndex = 0; switch (PBGetCatInfo (&CPB, 0)) { case noErr: break; case fnfErr: CPB.hFileInfo.ioDirID = 0; CPB.hFileInfo.ioVRefNum = vRef; err = PBGetCatInfo (&CPB, 0); break; default: return nil; } hfp.ioCompletion = nil; hfp.ioNamePtr = buf; hfp.ioVRefNum = CPB.hFileInfo.ioVRefNum; hfp.ioFDirIndex = 0; hfp.ioDirID = CPB.hFileInfo.ioDirID; if (err = PBHGetFInfo((HParmBlkPtr) &hfp, FALSE)) { print(catgets(catalog, CAT_MSGS, 1013, "autotyper: couldn't read attachment file information")); return nil; } /* creator default is Z-Mail sig */ d = (char *) kind; *((long *)(d)) = CPB.hFileInfo.ioFlFndrInfo.fdType; kind[4] = '/'; d += 5; *((long *)(d)) = CPB.hFileInfo.ioFlFndrInfo.fdCreator; kind[9] = 0; if (!type_mactypes) (void) get_attach_keys(0, (Attach *)0, NULL); d = get_type_from_mactype((char *)kind); if (!strcmp(d, kind)) d = nil; if (!d && hfp.ioFlRLgLen) d = "application/mac-binhex40"; return d; } /* autotype_via_mactype */
P2 (PUBLIC pascal trap, OSErr, FSpGetFInfo, FSSpecPtr, spec, FInfo *, fndr_info) { OSErr retval; HParamBlockRec hpb; hpb.fileParam.ioVRefNum = spec->vRefNum; hpb.fileParam.ioDirID = spec->parID; hpb.fileParam.ioNamePtr = (StringPtr) RM ((Ptr) spec->name); hpb.fileParam.ioFDirIndex = CWC (0); retval = PBHGetFInfo (&hpb, FALSE); if (retval == noErr) *fndr_info = hpb.fileParam.ioFlFndrInfo; return retval; }
P2 (PUBLIC pascal trap, OSErr, FSpSetFInfo, FSSpecPtr, spec, FInfo *, fndr_info) { OSErr retval; HParamBlockRec hpb; warning_unimplemented ("poorly implemented: call of PBHGetFInfo wasteful"); hpb.fileParam.ioVRefNum = spec->vRefNum; hpb.fileParam.ioDirID = spec->parID; hpb.fileParam.ioNamePtr = (StringPtr) RM ((Ptr) spec->name); hpb.fileParam.ioFDirIndex = CWC (0); retval = PBHGetFInfo (&hpb, FALSE); if (retval == noErr) { hpb.fileParam.ioDirID = spec->parID; hpb.fileParam.ioFlFndrInfo = *fndr_info; retval = PBHSetFInfo (&hpb, FALSE); } return retval; }
PUBLIC OSErr HCreate (INTEGER vref, LONGINT dirid, Str255 name, OSType creator, OSType type) { HParamBlockRec hpb; OSErr retval; hpb.fileParam.ioNamePtr = RM (name); hpb.fileParam.ioVRefNum = CW (vref); hpb.fileParam.ioDirID = CL (dirid); retval = PBHCreate (&hpb, FALSE); if (retval == noErr) { hpb.fileParam.ioFDirIndex = CWC (0); retval = PBHGetFInfo (&hpb, FALSE); if (retval == noErr) { hpb.fileParam.ioFlFndrInfo.fdCreator = CL (creator); hpb.fileParam.ioFlFndrInfo.fdType = CL (type); hpb.fileParam.ioDirID = CL (dirid); retval = PBHSetFInfo (&hpb, FALSE); } } return retval; }