file.c

Go to the documentation of this file.
00001 
00002 /*  $Id: file.c 1209 2006-04-05 23:59:59Z karstenw $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #ifdef MACVERSION
00032     #if TARGET_API_MAC_CARBON
00033         #include "MoreFilesX.h"
00034     #else
00035         #include "MoreFilesExtras.h"
00036     #endif
00037 #endif
00038 
00039 #include "filealias.h"
00040 #include "cursor.h"
00041 #include "dialogs.h"
00042 #include "error.h"
00043 #include "mac.h"
00044 #include "memory.h"
00045 #include "ops.h"
00046 #include "quickdraw.h"
00047 #include "resources.h"
00048 #include "strings.h"
00049 #include "frontierwindows.h"
00050 #include "file.h"
00051 #include "shell.h"
00052 #include "shell.rsrc.h"
00053 #include "langinternal.h" /*for langbackgroundtask*/
00054 
00055 
00056 #ifdef MACVERSION
00057 #ifdef flcomponent
00058 
00059     #include "SetUpA5.h"
00060 
00061 #endif
00062 #endif
00063 
00064 
00065 
00066 boolean equalfilespecs (const tyfilespec *fs1, const tyfilespec *fs2) {
00067     
00068     /*
00069     5.0a25 dmb: until we set the volumeID to zero for all Win fsspecs,
00070     we must not compare them here
00071     */
00072 
00073     #ifdef MACVERSION
00074         if ((*fs1).vRefNum != (*fs2).vRefNum)
00075             return (false);
00076         
00077         if ((*fs1).parID != (*fs2).parID)
00078             return (false);
00079         
00080         return (equalstrings ((ptrstring) fsname (fs1), (ptrstring) fsname (fs2)));
00081     #endif
00082     #ifdef WIN95VERSION
00083         //if ((*fs1).volumeID != (*fs2).volumeID)
00084         //  return (false);
00085         
00086         return (lstrcmp(fsname (fs1), fsname (fs2)) == 0);
00087 #endif
00088     } /*equalfilespecs*/
00089 
00090 
00091 boolean filesetposition (hdlfilenum fnum, long position) {
00092     
00093     /*
00094     5.0.2b6 dmb: report errors
00095     */
00096     
00097     #ifdef MACVERSION
00098         return (!oserror (SetFPos (fnum, fsFromStart, position)));
00099     #endif
00100 
00101     #ifdef WIN95VERSION
00102         if (SetFilePointer (fnum, position, NULL, FILE_BEGIN) == -1L) {
00103             
00104             winerror ();
00105             
00106             return (false);
00107             }
00108         
00109         return (true);
00110     #endif
00111     } /*filesetposition*/
00112     
00113     
00114 boolean filegetposition (hdlfilenum fnum, long *position) {
00115     
00116     #ifdef MACVERSION
00117         return (!oserror (GetFPos (fnum, position)));
00118     #endif
00119 
00120     #ifdef WIN95VERSION
00121         *position = SetFilePointer (fnum, 0L, NULL, FILE_CURRENT);
00122 
00123         if (*position == -1L) {
00124             
00125             winerror ();
00126 
00127             return (false);
00128             }
00129 
00130         return (true);
00131     #endif
00132     } /*filegetposition*/
00133 
00134 
00135 boolean filegeteof (hdlfilenum fnum, long *position) {
00136     
00137     #ifdef MACVERSION
00138         /*
00139         6/x/91 mao
00140         */
00141 
00142         return (!oserror (GetEOF (fnum, position)));
00143     #endif
00144 
00145     #ifdef WIN95VERSION
00146         long origpos;
00147 
00148         filegetposition (fnum, &origpos);
00149 
00150         *position = SetFilePointer (fnum, 0L, NULL, FILE_END);
00151 
00152         filesetposition (fnum, origpos);
00153 
00154         if (*position == -1L) {
00155             
00156             winerror ();
00157 
00158             return (false);
00159             }
00160 
00161         return (true);
00162     #endif
00163     } /*filegeteof*/
00164 
00165 
00166 boolean fileseteof (hdlfilenum fnum, long position) {
00167     
00168     /*
00169     5.0.2b6 dmb: report errors
00170     */
00171     
00172     #ifdef MACVERSION
00173         return (!oserror (SetEOF (fnum, position)));
00174     #endif
00175 
00176     #ifdef WIN95VERSION
00177         long currentPosition;
00178 
00179         currentPosition = SetFilePointer (fnum, 0L, NULL, FILE_CURRENT);
00180         
00181         if (currentPosition == -1L)
00182             goto error;
00183         
00184         if (SetFilePointer (fnum, position, NULL, FILE_BEGIN) == -1L)
00185             goto error;
00186         
00187         if (!SetEndOfFile (fnum))
00188             goto error;
00189                 
00190         if (SetFilePointer (fnum, currentPosition, NULL, FILE_BEGIN) == -1L)
00191             goto error;
00192         
00193         return (true);
00194         
00195     error:
00196         winerror ();
00197         
00198         return (false);
00199     #endif
00200     } /*fileseteof*/
00201 
00202 
00203 long filegetsize (hdlfilenum fnum) {
00204     
00205     /*
00206     get the size of a file that's already open.
00207     */
00208     
00209     #ifdef MACVERSION
00210         long lfilesize;
00211         
00212         if (GetEOF (fnum, &lfilesize) != noErr)
00213             lfilesize = 0;
00214         
00215         return (lfilesize);
00216     #endif
00217 
00218     #ifdef WIN95VERSION
00219         long lfilesize;
00220 
00221         lfilesize = GetFileSize (fnum, NULL);
00222         if (lfilesize == -1L)
00223             lfilesize = 0L;
00224 
00225         return (lfilesize);
00226     #endif
00227     } /*filegetsize*/
00228 
00229 
00230 boolean filetruncate (hdlfilenum fnum) {
00231     
00232     return (fileseteof (fnum, 0L));
00233     } /*filetruncate*/
00234 
00235 
00236 boolean filewrite (hdlfilenum fnum, long ctwrite, void *buffer) {
00237     
00238     /*
00239     write ctwrite bytes from buffer to the current position in file number
00240     fnum.  return true iff successful.
00241     */
00242 
00243     if (ctwrite > 0) {
00244         
00245         #ifdef MACVERSION
00246             if (oserror (FSWrite (fnum, &ctwrite, buffer)))
00247                 return (false);
00248         #endif
00249 
00250         #ifdef WIN95VERSION
00251             DWORD numberBytesWritten;
00252 
00253             if (WriteFile (fnum, buffer, ctwrite, &numberBytesWritten, NULL)) {
00254                 
00255                 if ((DWORD)ctwrite == numberBytesWritten)
00256                     return (true);
00257                 }
00258             
00259             winerror();
00260 
00261             return (false);
00262         #endif
00263         }
00264     
00265     return (true);
00266     } /*filewrite*/
00267 
00268 
00269 boolean filereaddata (hdlfilenum fnum, long ctread, long *ctactual, void *buffer) {
00270     
00271     /*
00272     lower level than fileread, we can read less than the number of 
00273     bytes requested.
00274     */
00275     
00276     *ctactual = ctread;
00277     
00278     if (ctread > 0) {
00279         
00280         #ifdef MACVERSION
00281             OSErr ec = FSRead (fnum, ctactual, buffer);
00282             
00283             if (ec != noErr && ec != eofErr) {
00284                 
00285                 oserror (ec);
00286                 
00287                 return (false);
00288                 }
00289         #endif
00290         
00291         #ifdef WIN95VERSION
00292             if (!ReadFile (fnum, buffer, ctread, ctactual, NULL)) {
00293                 
00294                 winerror ();
00295                 
00296                 return (false);
00297                 }
00298         #endif
00299         }
00300     
00301     return (true);
00302     } /*filereaddata*/
00303     
00304     
00305 boolean fileread (hdlfilenum fnum, long ctread, void *buffer) {
00306     
00307     /*
00308     read ctread bytes from the current position in file number fnum into
00309     the buffer.  return true iff successful.
00310     */
00311     
00312     long ctactual;
00313     
00314     if (!filereaddata (fnum, ctread, &ctactual, buffer))
00315         return (false);
00316     
00317     if (ctactual < ctread) {
00318         
00319         #ifdef MACVERSION
00320             oserror (eofErr);
00321         #endif
00322         #ifdef WIN95VERSION
00323             oserror (ERROR_HANDLE_EOF);
00324         #endif
00325 
00326         return (false);
00327         }
00328     
00329     return (true);
00330     } /*fileread*/
00331     
00332     
00333 boolean filegetchar (hdlfilenum fnum, char *ch) {
00334     
00335     /*
00336     long pos;
00337     
00338     if (!filegetposition (fnum, &pos))
00339         return (false);
00340         
00341     if (pos >= filegetsize (fnum)) {
00342         
00343         *fleof = true;
00344         
00345         return (true);
00346         }
00347     
00348     *fleof = false;
00349     */
00350     
00351     return (fileread (fnum, (long) 1, ch));
00352     } /*filegetchar*/
00353     
00354     
00355 boolean fileputchar (hdlfilenum fnum, char ch) {
00356     
00357     return (filewrite (fnum, (long) 1, &ch));
00358     } /*fileputchar*/
00359 
00360 
00361 boolean filewritehandle (hdlfilenum fnum, Handle h) {
00362     
00363     /*
00364     write the indicated handle to the open file indicated by fnum at the
00365     current position in the file.
00366     */
00367     
00368     return (filewrite (fnum, gethandlesize (h), *h));
00369     } /*filewritehandle*/
00370 
00371 
00372 /*
00373 static boolean filereadhandlebytes (short fnum, long ctbytes, Handle *hreturned) {
00374     
00375     /%
00376     6/x/91 mao
00377     this one is parallel to filewritehandle
00378     %/
00379     
00380     register Handle h;
00381     
00382     if (!newclearhandle (ctbytes, hreturned))
00383         return (false);
00384         
00385     h = *hreturned; /%copy into register%/
00386         
00387     if (oserror (fileread (fnum, ctbytes, *h))) {
00388         
00389         disposehandle (h);
00390         
00391         return (false);
00392         }
00393         
00394     return (true);
00395     } /%filereadhandlebytes%/
00396 */
00397 
00398 
00399 boolean filereadhandle (hdlfilenum fnum, Handle *hreturned) {
00400     
00401     /*
00402     not exactly parallel to filewritehandle.  we read the whole file into the 
00403     indicated handle and return true if it worked.
00404     */
00405     
00406     register long lfilesize;
00407     register Handle h;
00408     
00409     lfilesize = filegetsize (fnum);
00410     
00411     if (!newclearhandle (lfilesize, hreturned))
00412         return (false);
00413         
00414     h = *hreturned; /*copy into register*/
00415         
00416     if (!fileread (fnum, lfilesize, *h)) {
00417         
00418         disposehandle (h);
00419         
00420         return (false);
00421         }
00422         
00423     return (true);
00424     } /*filereadhandle*/
00425 
00426 
00427 #ifdef MACVERSION   
00428 
00429 //Code change by Timothy Paustian Monday, June 19, 2000 3:15:01 PM
00430 //Changed to Opaque call for Carbon
00431 
00432 static pascal void iocompletion (ParmBlkPtr pb) {
00433 
00434     DisposePtr ((Ptr) pb);
00435     } /*iocompletion*/
00436 
00437 
00438 #if TARGET_RT_MAC_CFM || TARGET_RT_MAC_MACHO
00439 
00440     #if TARGET_API_MAC_CARBON
00441 
00442         //looks like we need some kind of file UPP
00443         //do we need to create a UPP, yes we do.
00444         IOCompletionUPP iocompletionDesc = nil;
00445 
00446         #define iocompletionUPP (iocompletionDesc)
00447 
00448     #else
00449 
00450         static RoutineDescriptor iocompletionDesc = BUILD_ROUTINE_DESCRIPTOR (uppIOCompletionProcInfo, iocompletion);
00451 
00452         #define iocompletionUPP (&iocompletionDesc)
00453 
00454     #endif
00455 
00456 #else
00457 
00458     static IOCompletionUPP iocompletionUPP = &iocompletion;
00459 
00460 #endif
00461 
00462 #endif //MACVERSION
00463 
00464 boolean flushvolumechanges (const tyfilespec *fs, hdlfilenum fnum) {
00465 #ifdef MACVERSION
00466 #   pragma unused(fnum)
00467 
00468     /*
00469     4.1b7 dmb: was -- FlushVol (nil, (*fs).vRefNum);
00470     
00471     now use PB call to do asynch flush
00472     */
00473     
00474     ParamBlockRec *pb;
00475     
00476     pb = (ParamBlockRec *) NewPtrClear (sizeof (ParamBlockRec));
00477     
00478     (*pb).volumeParam.ioVRefNum = (*fs).vRefNum;
00479     
00480     (*pb).volumeParam.ioCompletion = iocompletionUPP;
00481     
00482     PBFlushVolAsync (pb);
00483 #endif  
00484 
00485 #ifdef WIN95VERSION
00486     if (fnum != NULL)
00487         FlushFileBuffers (fnum);
00488 #endif
00489     return (true);
00490     } /*flushvolumechanges*/
00491 
00492 //Code change by Timothy Paustian Wednesday, July 26, 2000 10:52:49 PM
00493 //new routine to create UPPS for the async file saves.
00494 void fileinit (void) {
00495     #if TARGET_API_MAC_CARBON
00496     if(iocompletionDesc == nil)
00497         iocompletionDesc = NewIOCompletionUPP(iocompletion);
00498     #endif
00499     } /*fileinit*/
00500 
00501 
00502 void fileshutdown(void) {
00503 
00504     #if TARGET_API_MAC_CARBON
00505     if(iocompletionDesc != nil)
00506         DisposeIOCompletionUPP(iocompletionDesc);
00507     #endif
00508     } /*fileshutdown*/
00509 
00510 
00511 static boolean filecreateandopen (const tyfilespec *fs, OSType creator, OSType filetype, hdlfilenum *fnum) {
00512 #ifdef MACVERSION   
00513         OSStatus    err = noErr;
00514 //      char        s[256];
00515         
00516     setfserrorparam (fs);
00517     
00518     if (oserror (FSpCreate (fs, creator, filetype, smSystemScript))) /*failed to open the file for writing*/
00519         return (false);
00520     
00521     if (oserror (FSpOpenDF (fs, fsRdWrPerm, fnum))) {
00522         
00523         FSClose (*fnum);
00524         
00525         deletefile (fs);
00526         
00527         return (false); /*failed to open the file for writing*/
00528         }
00529     
00530     #if TARGET_API_MAC_CARBON
00531         {
00532         FSRef   myRef;
00533         err = FSpMakeFSRef (fs,&myRef);
00534         if (!err)
00535             FSSetNameLocked(&myRef);
00536         }
00537     #endif
00538         
00539     return (true);
00540 #endif
00541 
00542 #ifdef WIN95VERSION
00543     HANDLE fref;
00544 
00545     fref = (Handle) CreateFile (stringbaseaddress (fsname (fs)), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ,
00546                                                 NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
00547     *fnum = 0;
00548 
00549     if (fref == INVALID_HANDLE_VALUE) {
00550         
00551         winfileerror (fs);
00552 
00553         return (false);
00554         }
00555 
00556     *fnum = (hdlfilenum) fref;
00557     return (true);
00558 #endif
00559     } /*filecreateandopen*/
00560 
00561 
00562 boolean fileopenorcreate (const tyfilespec *fs, OSType creator, OSType filetype, hdlfilenum *fnum) {
00563 #ifdef MACVERSION   
00564     /*
00565     open or create a file indicated by fs.  return with fnum set to the Mac 
00566     filesystem's file number for the file.
00567     
00568     if we open a file, we takes what we get in the creator and filetype department.
00569     however, if we create a file it's of the indicated filetype and creator.
00570     */
00571     
00572     if (FSpOpenDF (fs, fsRdWrPerm, fnum) == noErr) {
00573         /*file exists and is open*/
00574         #if TARGET_API_MAC_CARBON
00575             FSRef   myRef;
00576             if (FSpMakeFSRef (fs,&myRef))
00577                 FSSetNameLocked(&myRef);
00578         #else
00579             FSpSetNameLocked(&fs);
00580         #endif
00581         return (true);
00582     }
00583     return (filecreateandopen (fs, creator, filetype, fnum));
00584 #endif
00585 
00586 #ifdef WIN95VERSION
00587     HANDLE fref;
00588     DWORD dAccess;
00589     char fn[300];
00590 
00591     dAccess = GENERIC_READ | GENERIC_WRITE;
00592 
00593     copystring (fsname (fs), fn);
00594     
00595     nullterminate (fn);
00596 
00597     fref = (Handle) CreateFile (stringbaseaddress(fn), dAccess, FILE_SHARE_READ,
00598                                                 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
00599     *fnum = 0;
00600 
00601     if (fref == INVALID_HANDLE_VALUE) {
00602         
00603         winfileerror (fs);
00604 
00605         return (false);
00606         }
00607 
00608     *fnum = (hdlfilenum) fref;
00609     return (true);
00610 #endif
00611     } /*fileopenorcreate*/
00612 
00613 
00614 boolean opennewfile (const tyfilespec *fs, OSType creator, OSType filetype, hdlfilenum *fnum) {
00615     
00616     boolean flfolder;
00617     
00618     if (fileexists (fs, &flfolder)) { /*file exists, delete it*/
00619         //WriteToConsole("We're deleting a file that already exists. No idea why.");
00620         if (!deletefile (fs))
00621             return (false);
00622         }
00623     
00624     return (filecreateandopen (fs, creator, filetype, fnum));
00625     } /*opennewfile*/
00626 
00627 
00628 boolean openfile (const tyfilespec *fs, hdlfilenum *fnum, boolean flreadonly) {
00629     
00630 #ifdef MACVERSION
00631     /*
00632     5/23/91 dmb: make sure we clear fnum on error; if file is already open, 
00633     FSOpen will set fnum to the existing channel
00634     
00635     4.1b4 dmb: added flreadonly paramater
00636     */
00637     
00638     OSErr errcode;
00639     OSErr err = noErr;
00640     short perm;
00641     
00642     setfserrorparam (fs); /*in case error message takes a filename parameter*/
00643     
00644     if (flreadonly)
00645         perm = fsRdPerm;
00646     else
00647         perm = fsRdWrPerm;
00648 
00649     errcode = FSpOpenDF (fs, perm, fnum);
00650     
00651     if (oserror (errcode)) {
00652         
00653         *fnum = 0;
00654         
00655         return (false);
00656         }
00657     #if TARGET_API_MAC_CARBON
00658         {
00659         FSRef   myRef;
00660         err = FSpMakeFSRef (fs,&myRef);
00661         if (!err)
00662             err = FSSetNameLocked(&myRef);
00663         }
00664     #else
00665         err = FSpSetNameLocked(fs);
00666     #endif
00667     
00668     if (err!=noErr){
00669         //sprintf(s,"error locking file name: %d",err);
00670         //WriteToConsole(s);
00671     }
00672     
00673     return (true);
00674 #endif
00675 
00676 #ifdef WIN95VERSION
00677     HANDLE fref;
00678     DWORD dAccess;
00679     char fn[300];
00680 
00681     if (flreadonly)
00682         dAccess = GENERIC_READ;
00683     else
00684         dAccess = GENERIC_READ | GENERIC_WRITE;
00685 
00686     copystring (fsname (fs), fn);
00687 
00688     nullterminate (fn);
00689 
00690     fref = (Handle) CreateFile (stringbaseaddress(fn), dAccess, FILE_SHARE_READ,
00691                                                 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
00692     *fnum = 0;
00693 
00694     if (fref == INVALID_HANDLE_VALUE) {
00695         
00696         winfileerror (fs);
00697 
00698         return (false);
00699         }
00700 
00701     *fnum = (hdlfilenum) fref;
00702     return (true);
00703 #endif
00704     } /*openfile*/
00705     
00706 /*******
00707 
00708 From MoreFilesExtras. 
00709 I'm going to use this to yank the fsspec back out from a refnum,
00710 so that I can clear the finder name lock from the file prior to closing it.
00711 
00712 *******/
00713     
00714     
00715 boolean closefile (hdlfilenum fnum) {
00716 #ifdef MACVERSION   
00717     OSStatus    err = noErr;
00718 //  char        s[256];
00719         
00720     /*
00721     dmb 8/20/90:  check for 0.
00722     */
00723     
00724     if (fnum != 0) {
00725         #if TARGET_API_MAC_CARBON
00726             FSRef myRef;
00727             err = FileRefNumGetFSRef (fnum, &myRef);
00728             if (err == noErr) {
00729                 FSClearNameLocked (&myRef);
00730                 }
00731         #else
00732             FSSpec fs;
00733             err = FSpGetFileLocation (fnum,&fs);
00734             if (err==noErr) {
00735                 FSpClearNameLocked (&fs);
00736                 }
00737         #endif
00738             else {
00739                 //sprintf(s,"Error is %d",err);
00740                 //WriteToConsole(s);
00741                 }
00742                 
00743         return (!oserror (FSClose (fnum)));
00744         }
00745     
00746     return (true);
00747 #endif
00748 
00749 #ifdef WIN95VERSION
00750     if (fnum != 0) {
00751         
00752         if (!CloseHandle (fnum)) {
00753             
00754             winerror ();
00755 
00756             return (false);
00757             }
00758         }
00759     
00760     return (true);
00761 #endif
00762     } /*closefile*/
00763 
00764 
00765 boolean deletefile (const tyfilespec *fs) {
00766     
00767     /* 
00768     2.1b2 dmb: new filespec-based version
00769 
00770     5.0.1 dmb: always setsferror param
00771     */
00772     
00773     #ifdef MACVERSION
00774         setfserrorparam (fs); /*in case error message takes a filename parameter*/
00775         #if TARGET_API_MAC_CARBON
00776             {
00777             FSRef   myRef;
00778             if (FSpMakeFSRef (fs,&myRef))
00779                 FSClearNameLocked(&myRef);
00780             }
00781         #else
00782             FSpClearNameLocked(fs);
00783         #endif
00784         return (!oserror (FSpDelete (fs)));
00785     #endif
00786 
00787     #ifdef WIN95VERSION
00788         char fn[300];
00789         boolean fldeletefolder;
00790 
00791         setfserrorparam (fs); /*in case error message takes a filename parameter*/
00792         
00793         copystring (fsname (fs), fn);
00794 
00795         cleanendoffilename(fn);
00796 
00797         nullterminate (fn);
00798 
00799         if (!fileisfolder (fs, &fldeletefolder))
00800             return (false);
00801 
00802         if (fldeletefolder) {
00803             
00804             if (RemoveDirectory (stringbaseaddress(fn)))
00805                 return (true);
00806             
00807             goto error;
00808             }
00809 
00810         if (DeleteFile (stringbaseaddress(fn)))
00811             return (true);
00812 
00813     error:
00814         winerror ();
00815 
00816         return (false);
00817     #endif
00818     } /*deletefile*/
00819     
00820 
00821 
00822 boolean fileexists (const tyfilespec *fs, boolean *flfolder) {
00823 #ifdef MACVERSION   
00824     /*
00825     we figure if we can get info on it, it must exist.
00826     
00827     can't call filegetinfo because it has an error message if the file 
00828     isn't found.
00829     
00830     7/1/91 dmb: special case empty string so we don't try to get info about 
00831     the default volume and return true.
00832     
00833     2.1b2 dmb: filespec implementation
00834     
00835     5.0.2b15 rab: return false to non-existent volume specs.
00836     */
00837     
00838     CInfoPBRec pb;
00839     
00840     *flfolder = false;
00841     
00842     if (isemptystring (fsname (fs)))
00843         return (false);
00844     
00845     clearbytes (&pb, sizeof (pb));
00846     
00847     pb.hFileInfo.ioNamePtr = (StringPtr) fsname (fs);
00848     
00849     pb.hFileInfo.ioVRefNum = (*fs).vRefNum;
00850     
00851     pb.hFileInfo.ioDirID = (*fs).parID;
00852     
00853     if (PBGetCatInfoSync (&pb) != noErr)
00854         return (false);
00855     
00856     *flfolder = foldertest (&pb);
00857     
00858     return (true);
00859 #endif
00860 #ifdef WIN95VERSION
00861     HANDLE ff;
00862     WIN32_FIND_DATA ffd;
00863     char fn[300];
00864 
00865     *flfolder = false;
00866 
00867     copystring (fsname (fs), fn);
00868 
00869     /*if ends with \ get ride of it... and handle the root*/
00870 
00871     cleanendoffilename (fn);
00872 
00873     nullterminate (fn);
00874 
00875     if (stringlength(fn) == 2) {
00876         if (isalpha(fn[1]) && fn[2] == ':') {
00877             *flfolder = true;
00878             return (fileisvolume(fs));
00879             }
00880         }
00881 
00882     ff = FindFirstFile (stringbaseaddress(fn), &ffd);
00883 
00884     if (ff == INVALID_HANDLE_VALUE)
00885         return (false);
00886 
00887     *flfolder = ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY?true:false;
00888 
00889     FindClose (ff);
00890     return (true);
00891 #endif
00892     } /*fileexists*/
00893 
00894 
00895 boolean filegetfilename (const tyfilespec *pfs, bigstring name) {
00896 
00897 #ifdef MACVERSION
00898     /*
00899     filespecs for volumes have their strings set to the empty string.
00900     */
00901     
00902     copystring (fsname (pfs), name);
00903     
00904     if (stringlength (name) > 0)
00905         return (true);
00906         
00907     return (filegetvolumename ((*pfs).vRefNum, name));
00908 #endif
00909 
00910 #ifdef WIN95VERSION
00911     lastword ((ptrstring) fsname (pfs), '\\', name);
00912 
00913     return (true);
00914 #endif
00915     } /*filegetfilename*/
00916 

Generated on Wed May 31 18:19:46 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6