]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/morefile/FullPath.h
   2 **      Apple Macintosh Developer Technical Support 
   4 **      Routines for dealing with full pathnames... if you really must. 
   6 **      by Jim Luther, Apple Developer Technical Support Emeritus 
  10 **      Copyright © 1995-1998 Apple Computer, Inc. 
  11 **      All rights reserved. 
  13 **      You may incorporate this sample code into your applications without 
  14 **      restriction, though the sample code has been provided "AS IS" and the 
  15 **      responsibility for its operation is 100% yours.  However, what you are 
  16 **      not permitted to do is to redistribute the source as "DSC Sample Code" 
  17 **      after having made changes. If you're going to re-distribute the source, 
  18 **      we require that you make it clear in the source that the code was 
  19 **      descended from Apple Sample Code, but that you've made changes. 
  37         The use of full pathnames is strongly discouraged. Full pathnames are 
  38         particularly unreliable as a means of identifying files, directories 
  39         or volumes within your application, for two primary reasons: 
  41         ¥      The user can change the name of any element in the path at 
  43         ¥      Volume names on the Macintosh are *not* unique. Multiple 
  44                 mounted volumes can have the same name. For this reason, the use of 
  45                 a full pathname to identify a specific volume may not produce the 
  46                 results you expect. If more than one volume has the same name and 
  47                 a full pathname is used, the File Manager currently uses the first 
  48                 mounted volume it finds with a matching name in the volume queue. 
  50         In general, you should use a fileÕs name, parent directory ID, and 
  51         volume reference number to identify a file you want to open, delete, 
  52         or otherwise manipulate. 
  54         If you need to remember the location of a particular file across 
  55         subsequent system boots, use the Alias Manager to create an alias 
  56         record describing the file. If the Alias Manager is not available, you 
  57         can save the fileÕs name, its parent directory ID, and the name of the 
  58         volume on which itÕs located. Although none of these methods is 
  59         foolproof, they are much more reliable than using full pathnames to 
  62         Nonetheless, it is sometimes useful to display a fileÕs full pathname 
  63         to the user. For example, a backup utility might display a list of full 
  64         pathnames of files as it copies them onto the backup medium. Or, a 
  65         utility might want to display a dialog box showing the full pathname of 
  66         a file when it needs the userÕs confirmation to delete the file. No 
  67         matter how unreliable full pathnames may be from a file-specification 
  68         viewpoint, users understand them more readily than volume reference 
  69         numbers or directory IDs. (Hint: Use the TruncString function from 
  70         TextUtils.h with truncMiddle as the truncWhere argument to shorten 
  71         full pathnames to a displayable length.) 
  73         The following technique for constructing the full pathname of a file is 
  74         intended for display purposes only. Applications that depend on any 
  75         particular structure of a full pathname are likely to fail on alternate 
  76         foreign file systems or under future system software versions. 
  79 /*****************************************************************************/ 
  81 pascal  OSErr   
GetFullPath(short vRefNum
, 
  83                                                         ConstStr255Param name
, 
  84                                                         short *fullPathLength
, 
  86 /*      ¦ Get a full pathname to a volume, directory or file. 
  87         The GetFullPath function builds a full pathname to the specified 
  88         object. The full pathname is returned in the newly created handle 
  89         fullPath and the length of the full pathname is returned in 
  90         fullPathLength. Your program is responsible for disposing of the 
  93         Note that a full pathname can be made to a file/directory that does not 
  94         yet exist if all directories up to that file/directory exist. In this case, 
  95         GetFullPath will return a fnfErr. 
  97         vRefNum                 input:  Volume specification. 
  98         dirID                   input:  Directory ID. 
  99         name                    input:  Pointer to object name, or nil when dirID 
 100                                                         specifies a directory that's the object. 
 101         fullPathLength  output: The number of characters in the full pathname. 
 102                                                         If the function fails to create a full 
 103                                                         pathname, it sets fullPathLength to 0. 
 104         fullPath                output: A handle to the newly created full pathname 
 105                                                         buffer. If the function fails to create a 
 106                                                         full pathname, it sets fullPath to NULL. 
 110                 nsvErr                          -35             No such volume 
 112                 bdNamErr                        -37             Bad filename 
 113                 fnfErr                          -43             File or directory does not exist (fullPath 
 114                                                                         and fullPathLength are still valid) 
 115                 paramErr                        -50             No default volume 
 116                 memFullErr                      -108    Not enough memory 
 117                 dirNFErr                        -120    Directory not found or incomplete pathname 
 118                 afpAccessDenied         -5000   User does not have the correct access 
 119                 afpObjectTypeErr        -5025   Directory not found or incomplete pathname 
 123         See also:       FSpGetFullPath 
 126 /*****************************************************************************/ 
 128 pascal  OSErr   
FSpGetFullPath(const FSSpec 
*spec
, 
 129                                                            short *fullPathLength
, 
 131 /*      ¦ Get a full pathname to a volume, directory or file. 
 132         The GetFullPath function builds a full pathname to the specified 
 133         object. The full pathname is returned in the newly created handle 
 134         fullPath and the length of the full pathname is returned in 
 135         fullPathLength. Your program is responsible for disposing of the 
 138         Note that a full pathname can be made to a file/directory that does not 
 139         yet exist if all directories up to that file/directory exist. In this case, 
 140         FSpGetFullPath will return a fnfErr. 
 142         spec                    input:  An FSSpec record specifying the object. 
 143         fullPathLength  output: The number of characters in the full pathname. 
 144                                                         If the function fails to create a full pathname, 
 145                                                         it sets fullPathLength to 0. 
 146         fullPath                output: A handle to the newly created full pathname 
 147                                                         buffer. If the function fails to create a 
 148                                                         full pathname, it sets fullPath to NULL. 
 152                 nsvErr                          -35             No such volume 
 154                 bdNamErr                        -37             Bad filename 
 155                 fnfErr                          -43             File or directory does not exist (fullPath 
 156                                                                         and fullPathLength are still valid) 
 157                 paramErr                        -50             No default volume 
 158                 memFullErr                      -108    Not enough memory 
 159                 dirNFErr                        -120    Directory not found or incomplete pathname 
 160                 afpAccessDenied         -5000   User does not have the correct access 
 161                 afpObjectTypeErr        -5025   Directory not found or incomplete pathname 
 165         See also:       GetFullPath 
 168 /*****************************************************************************/ 
 170 pascal OSErr 
FSpLocationFromFullPath(short fullPathLength
, 
 171                                                                          const void *fullPath
, 
 173 /*      ¦ Get a FSSpec from a full pathname. 
 174         The FSpLocationFromFullPath function returns a FSSpec to the object 
 175         specified by full pathname. This function requires the Alias Manager. 
 177         fullPathLength  input:  The number of characters in the full pathname 
 179         fullPath                input:  A pointer to a buffer that contains the full 
 180                                                         pathname of the target. The full pathname 
 181                                                         starts with the name of the volume, includes 
 182                                                         all of the directory names in the path to the 
 183                                                         target, and ends with the target name. 
 184         spec                    output: An FSSpec record specifying the object. 
 188                 nsvErr                          -35             The volume is not mounted 
 189                 fnfErr                          -43             Target not found, but volume and parent 
 191                 paramErr                        -50             Parameter error 
 192                 usrCanceledErr          -128    The user canceled the operation 
 196         See also:       LocationFromFullPath 
 199 /*****************************************************************************/ 
 201 pascal OSErr 
LocationFromFullPath(short fullPathLength
, 
 202                                                                   const void *fullPath
, 
 206 /*      ¦ Get an object's location from a full pathname. 
 207         The LocationFromFullPath function returns the volume reference number, 
 208         parent directory ID and name of the object specified by full pathname. 
 209         This function requires the Alias Manager. 
 211         fullPathLength  input:  The number of characters in the full pathname 
 213         fullPath                input:  A pointer to a buffer that contains the full 
 214                                                         pathname of the target. The full pathname starts 
 215                                                         with the name of the volume, includes all of 
 216                                                         the directory names in the path to the target, 
 217                                                         and ends with the target name. 
 218         vRefNum                 output: The volume reference number. 
 219         parID                   output: The parent directory ID of the specified object. 
 220         name                    output: The name of the specified object. 
 224                 nsvErr                          -35             The volume is not mounted 
 225                 fnfErr                          -43             Target not found, but volume and parent 
 227                 paramErr                        -50             Parameter error 
 228                 usrCanceledErr          -128    The user canceled the operation 
 232         See also:       FSpLocationFromFullPath 
 235 /*****************************************************************************/ 
 241 #include "OptimEnd.h" 
 243 #endif  /* __FULLPATH__ */