portability_guide.htm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
  5. <meta name="ProgId" content="FrontPage.Editor.Document">
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7. <title>Portability Guide</title>
  8. <link href="styles.css" rel="stylesheet">
  9. </head>
  10. <body bgcolor="#FFFFFF">
  11. <h1>
  12. <img border="0" src="../../../boost.png" align="center" width="300" height="86">Path
  13. Name Portability
  14. Guide</h1>
  15. <table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse"
  16. bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
  17. <tr>
  18. <td><a href="index.htm">Home</a> &nbsp;&nbsp;
  19. <a href="tutorial.html">Tutorial</a> &nbsp;&nbsp;
  20. <a href="reference.html">Reference</a> &nbsp;&nbsp;
  21. <a href="faq.htm">FAQ</a> &nbsp;&nbsp;
  22. <a href="release_history.html">Releases</a> &nbsp;&nbsp;
  23. <a href="portability_guide.htm">Portability</a> &nbsp;&nbsp;
  24. <a href="v3.html">V3 Intro</a> &nbsp;&nbsp;
  25. <a href="v3_design.html">V3 Design</a> &nbsp;&nbsp;
  26. <a href="deprecated.html">Deprecated</a> &nbsp;&nbsp;
  27. <a href="issue_reporting.html">Bug Reports </a>&nbsp;&nbsp;
  28. </td>
  29. </table>
  30. <p>
  31. <a href="#Introduction">Introduction</a><br>
  32. <a href="#name_check_functions">name_check functions</a><br>
  33. <a href="#recommendations">File and directory name recommendations</a></p>
  34. <h2><a name="Introduction">Introduction</a></h2>
  35. <p>Like any other C++ program which performs I/O operations, there is no
  36. guarantee that a program using Boost.Filesystem will be portable between
  37. operating systems. Critical aspects of I/O such as how the operating system
  38. interprets paths are unspecified by the C and C++ Standards.</p>
  39. <p>It is not possible to know if a file or directory name will be
  40. valid (and thus portable) for an unknown operating system. There is always the possibility that an operating system could use
  41. names which are unusual (numbers less than 4096, for example) or very
  42. limited in size (maximum of six character names, for example). In other words,
  43. portability is never absolute; it is always relative to specific operating
  44. systems or
  45. file systems.</p>
  46. <p>It is possible, however, to know in advance if a directory or file name is likely to be valid for a particular
  47. operating system.&nbsp;It is also possible to construct names which are
  48. likely to be portable to a large number of modern and legacy operating systems.</p>
  49. <p>Almost all modern operating systems support multiple file systems. At the
  50. minimum, they support a native file system plus a CD-ROM file system (Generally
  51. ISO-9669, often with Joliet extensions).</p>
  52. <p>Each file system
  53. may have its own naming rules. For example, modern versions of Windows support NTFS, FAT, FAT32, and ISO-9660 file systems, among others, and the naming rules
  54. for those file systems differ. Each file system may also have
  55. differing rules for overall path validity, such as a maximum length or number of
  56. sub-directories. Some legacy systems have different rules for directory names
  57. versus regular file names.</p>
  58. <p>As a result, Boost.Filesystem's <i>name_check</i> functions
  59. cannot guarantee directory and file name portability. Rather, they are intended to
  60. give the programmer a &quot;fighting chance&quot; to achieve portability by early
  61. detection of common naming problems.</p>
  62. <h2><a name="name_check_functions">name_check functions</a></h2>
  63. <p>A <i>name_check</i> function
  64. returns true if its argument is valid as a directory and regular file name for a
  65. particular operating or file system. A number of these functions are provided.</p>
  66. <p>The <a href="#portable_name">portable_name</a> function is of particular
  67. interest because it has been carefully designed to provide wide
  68. portability yet not overly restrict expressiveness.</p>
  69. <table border="1" cellpadding="5" cellspacing="0">
  70. <tr>
  71. <td align="center" colspan="2"><b>Library Supplied name_check Functions</b></td>
  72. </tr>
  73. <tr>
  74. <td align="center"><b>Function</b></td>
  75. <td align="center"><b>Description</b></td>
  76. </tr>
  77. <tr>
  78. <td align="left" valign="top"><code><a name="portable_posix_name">portable_posix_name</a>(const
  79. std::string&amp;<i> name</i>)</code></td>
  80. <td><b>Returns:</b> <i>true</i> if <code>!name.empty() &amp;&amp; name</code> contains only the characters
  81. specified in<i> Portable Filename Character Set</i> rules as defined in by
  82. POSIX (<a href="http://www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap03.html">www.opengroup.org/onlinepubs/007904975/basedefs/xbd_chap03.html</a>).<br>
  83. The allowed characters are <code>0-9</code>, <code>a-z</code>, <code>A-Z</code>,
  84. <code>'.'</code>, <code>'_'</code>, and <code>'-'</code>.<p><b>Use:</b>
  85. applications which must be portable to any POSIX system.</td>
  86. </tr>
  87. <tr>
  88. <td align="left" valign="top"><code><a name="windows_name">windows_name</a>(const
  89. std::string&amp;<i> name</i>)</code></td>
  90. <td><b>Returns:</b>&nbsp; <i>true</i> if <code>!name.empty() &amp;&amp; name</code> contains
  91. only the characters specified by the Windows platform SDK as valid
  92. regardless of the file system <code>&amp;&amp; (name</code> is <code>&quot;.&quot;</code> or
  93. <code>&quot;..&quot;</code>&nbsp; or does not end with a trailing space or period<code>)</code>.&nbsp;
  94. The allowed characters are anything except <code>0x0-0x1F</code>, <code>'&lt;'</code>,
  95. <code>'&gt;'</code>, <code>':'</code>, <code>'&quot;'</code>, <code>'/'</code>,
  96. <code>'\'</code>, and <code>'|'</code>.<p>
  97. <b>Use:</b> applications which must be portable to Windows.</p>
  98. <p><b>Note:</b> Reserved device names are not valid as file names, but are
  99. not being detected because they are still valid as a path. Specifically,
  100. CON, PRN, AUX, CLOCK$, NUL, COM[1-9], LPT[1-9], and these names followed by
  101. an extension (for example, NUL.tx7).</td>
  102. </tr>
  103. <tr>
  104. <td align="left" valign="top"><code><a name="portable_name">portable_name</a>(const
  105. std::string&amp;<i> name</i>)</code></td>
  106. <td><b>Returns:</b> <code>&nbsp;windows_name(name) &amp;&amp; portable_posix_name(name)
  107. &amp;&amp; (name</code> is <code>&quot;.&quot;</code> or <code>&quot;..&quot;</code>, and the first character not a period or hyphen<code>)</code>.<p><b>Use:</b> applications which must be portable to a wide variety of
  108. modern operating systems, large and small, and to some legacy O/S's. The
  109. first character not a period or hyphen restriction is a requirement of
  110. several older operating systems.</td>
  111. </tr>
  112. <tr>
  113. <td align="left" valign="top"><code><a name="portable_directory_name">
  114. portable_directory_name</a>(const std::string&amp;<i> name</i>)</code></td>
  115. <td><b>Returns:</b> <code>portable_name(name) &amp;&amp; (name</code> is <code>&quot;.&quot;</code>
  116. or <code>&quot;..&quot;</code>&nbsp; or contains no periods<code>)</code>.<p><b>Use:</b> applications
  117. which must be portable to a wide variety of platforms, including OpenVMS.</td>
  118. </tr>
  119. <tr>
  120. <td align="left" valign="top"><code><a name="portable_file_name">
  121. portable_file_name</a>(const std::string&amp;<i> name</i>)</code></td>
  122. <td><b>Returns:</b> <code>portable_name(name) &amp;&amp; </code>any period is followed by one to three additional
  123. non-period characters.<p><b>Use:</b>
  124. applications which must be portable to a wide variety of platforms,
  125. including OpenVMS and other systems which have a concept of &quot;file extension&quot;
  126. but limit its length.</td>
  127. </tr>
  128. <tr>
  129. <td align="left" valign="top"><code><a name="native">native</a>(const
  130. std::string&amp;<i> name</i>)</code></td>
  131. <td><b>Returns:</b> Implementation defined. Returns <i>
  132. true</i> for names considered valid by the operating system's native file
  133. systems.<p><b>Note:</b> May return <i>true</i> for some names not considered valid
  134. by the operating system under all conditions (particularly on operating systems which support
  135. multiple file systems.)</td>
  136. </tr>
  137. </table>
  138. <h2>File and directory name <a name="recommendations">recommendations</a></h2>
  139. <table border="1" cellpadding="5" cellspacing="0">
  140. <tr>
  141. <td align="center" valign="top"><strong>Recommendation</strong></td>
  142. <td align="center" valign="top"><strong>Rationale</strong></td>
  143. </tr>
  144. <tr>
  145. <td valign="top">Limit file and directory names to the characters A-Z, a-z, 0-9, period, hyphen, and
  146. underscore.<p>Use any of the &quot;portable_&quot; <a href="#name_check_functions">
  147. name check functions</a> to enforce this recommendation.</td>
  148. <td valign="top">These are the characters specified by the POSIX standard for portable directory and
  149. file names, and are also valid for Windows, Mac, and many other modern file systems.</td>
  150. </tr>
  151. <tr>
  152. <td valign="top">Do not use a period or hyphen as the first
  153. character of a name. Do not use period as the last character of a name.<p>
  154. Use <a href="#portable_name">portable_name</a>,
  155. <a href="#portable_directory_name">portable_directory_name</a>, or
  156. <a href="#portable_file_name">portable_file_name</a> to enforce this
  157. recommendation.</td>
  158. <td valign="top">Some operating systems treat have special rules for the
  159. first character of names. POSIX, for example. Windows does not permit period
  160. as the last character.</td>
  161. </tr>
  162. <tr>
  163. <td valign="top">Do not use periods in directory names.<p>Use
  164. <a href="#portable_directory_name">portable_directory_name</a> to enforce
  165. this recommendation.</td>
  166. <td valign="top">Requirement for ISO-9660 without Juliet extensions, OpenVMS filesystem, and other legacy systems.</td>
  167. </tr>
  168. <tr>
  169. <td valign="top">Do not use more that one period in a file name, and limit
  170. the portion after the period to three characters.<p>Use
  171. <a href="#portable_file_name">portable_file_name</a> to enforce this
  172. recommendation.</td>
  173. <td valign="top">Requirement for ISO-9660 level 1, OpenVMS filesystem, and
  174. other legacy systems. </td>
  175. </tr>
  176. <tr>
  177. <td valign="top">Do not assume names are case sensitive. For example, do not expected a directory to be
  178. able to hold separate elements named &quot;Foo&quot; and &quot;foo&quot;. </td>
  179. <td valign="top">Some file systems are case insensitive.&nbsp; For example, Windows
  180. NTFS is case preserving in the way it stores names, but case insensitive in
  181. searching for names (unless running under the POSIX sub-system, it which
  182. case it does case sensitive searches). </td>
  183. </tr>
  184. <tr>
  185. <td valign="top">Do not assume names are case insensitive.&nbsp; For example, do not expect a file
  186. created with the name of &quot;Foo&quot; to be opened successfully with the name of &quot;foo&quot;.</td>
  187. <td valign="top">Some file systems are case sensitive.&nbsp; For example, POSIX.</td>
  188. </tr>
  189. <tr>
  190. <td valign="top">Don't use hyphens in names.</td>
  191. <td valign="top">ISO-9660 level 1, and possibly some legacy systems, do not permit
  192. hyphens.</td>
  193. </tr>
  194. <tr>
  195. <td valign="top">Limit the length of the string returned by path::string() to
  196. 255 characters.&nbsp;
  197. Note that ISO 9660 has an explicit directory tree depth limit of 8, although
  198. this depth limit is removed by the Juliet extensions.</td>
  199. <td valign="top">Some operating systems place limits on the total path length.&nbsp; For example,
  200. Windows 2000 limits paths to 260 characters total length.</td>
  201. </tr>
  202. <tr>
  203. <td valign="top">Limit the length of any one name in a path.&nbsp; Pick the specific limit according to
  204. the operating systems and or file systems you wish portability to:<br>
  205. &nbsp;&nbsp; Not a concern::&nbsp; POSIX, Windows, MAC OS X.<br>
  206. &nbsp;&nbsp; 31 characters: Classic Mac OS<br>
  207. &nbsp;&nbsp; 8 characters + period + 3 characters: ISO 9660 level 1<br>
  208. &nbsp;&nbsp; 32 characters: ISO 9660 level 2 and 3<br>
  209. &nbsp;&nbsp; 128 characters (64 if Unicode): ISO 9660 with Juliet extensions</td>
  210. <td valign="top">Limiting name length can markedly reduce the expressiveness of file names, yet placing
  211. only very high limits on lengths inhibits widest portability.</td>
  212. </tr>
  213. </table>
  214. <hr>
  215. <p>Revised
  216. <!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->29 December, 2014<!--webbot bot="Timestamp" endspan i-checksum="38652" --></p>
  217. <p>&copy; Copyright Beman Dawes, 2002, 2003</p>
  218. <p> Use, modification, and distribution are subject to the Boost Software
  219. License, Version 1.0. (See accompanying file <a href="../../../LICENSE_1_0.txt">
  220. LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
  221. www.boost.org/LICENSE_1_0.txt</a>)</p>
  222. </body>
  223. </html>