Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
pathchk.html (16692B)
1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved --> 2 <!DOCTYPE HTML> 3 <html lang="en"> 4 <head> 5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0"> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 --> 8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved --> 9 <title>pathchk</title> 10 </head> 11 <body bgcolor="white"> 12 <div class="NAVHEADER"> 13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 14 <tr class="nav"> 15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/patch.html" accesskey="P"><<< 16 Previous</a></td> 17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/pax.html" accesskey="N">Next >>></a></td> 19 </tr> 20 </table> 21 <hr align="left" width="100%"></div> 22 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> 23 <center><font size="2">The Open Group Base Specifications Issue 8<br> 24 IEEE Std 1003.1-2024<br> 25 Copyright © 2001-2024 The IEEE and The Open Group</font></center> 26 <hr size="2" noshade> 27 <a name="top" id="top"></a> <a name="pathchk" id="pathchk"></a> <a name="tag_20_93" id="tag_20_93"></a><!-- pathchk --> 28 <h4 class="mansect"><a name="tag_20_93_01" id="tag_20_93_01"></a>NAME</h4> 29 <blockquote>pathchk — check pathnames</blockquote> 30 <h4 class="mansect"><a name="tag_20_93_02" id="tag_20_93_02"></a>SYNOPSIS</h4> 31 <blockquote class="synopsis"> 32 <p><code><tt>pathchk</tt> <b>[</b><tt>-p</tt><b>] [</b><tt>-P</tt><b>]</b> <i>pathname</i><tt>...</tt></code></p> 33 </blockquote> 34 <h4 class="mansect"><a name="tag_20_93_03" id="tag_20_93_03"></a>DESCRIPTION</h4> 35 <blockquote> 36 <p>The <i>pathchk</i> utility shall check that one or more pathnames are valid (that is, they could be used to access or create a 37 file without causing syntax errors) and portable (that is, no filename truncation results). More extensive portability checks are 38 provided by the <b>-p</b> and <b>-P</b> options.</p> 39 <p>By default, the <i>pathchk</i> utility shall check each component of each <i>pathname</i> operand based on the underlying file 40 system. A diagnostic shall be written for each <i>pathname</i> operand that:</p> 41 <ul> 42 <li> 43 <p>Is longer than {PATH_MAX} bytes (see <b>Pathname Variable Values</b> in XBD <a href= 44 "../basedefs/limits.h.html"><i><limits.h></i></a> )</p> 45 </li> 46 <li> 47 <p>Contains any component longer than {NAME_MAX} bytes in its containing directory</p> 48 </li> 49 <li> 50 <p>Contains any component in a directory that is not searchable</p> 51 </li> 52 <li> 53 <p>Contains any byte sequence that is not valid in its containing directory</p> 54 </li> 55 </ul> 56 <p>The format of the diagnostic message is not specified, but shall indicate the error detected and the corresponding 57 <i>pathname</i> operand.</p> 58 <p>It shall not be considered an error if one or more components of a <i>pathname</i> operand do not exist as long as a file 59 matching the pathname specified by the missing components could be created that does not violate any of the checks specified 60 above.</p> 61 </blockquote> 62 <h4 class="mansect"><a name="tag_20_93_04" id="tag_20_93_04"></a>OPTIONS</h4> 63 <blockquote> 64 <p>The <i>pathchk</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax 65 Guidelines</i></a> .</p> 66 <p>The following option shall be supported:</p> 67 <dl compact> 68 <dd></dd> 69 <dt><b>-p</b></dt> 70 <dd>Instead of performing checks based on the underlying file system, write a diagnostic for each <i>pathname</i> operand that: 71 <ul> 72 <li> 73 <p>Is longer than {_POSIX_PATH_MAX} bytes (see <b>Minimum Values</b> in XBD <a href= 74 "../basedefs/limits.h.html"><i><limits.h></i></a> )</p> 75 </li> 76 <li> 77 <p>Contains any component longer than {_POSIX_NAME_MAX} bytes</p> 78 </li> 79 <li> 80 <p>Contains any character in any component that is not in the portable filename character set</p> 81 </li> 82 </ul> 83 </dd> 84 <dt><b>-P</b></dt> 85 <dd>Write a diagnostic for each <i>pathname</i> operand that: 86 <ul> 87 <li> 88 <p>Contains a component whose first character is the <hyphen-minus> character</p> 89 </li> 90 <li> 91 <p>Is empty</p> 92 </li> 93 </ul> 94 </dd> 95 </dl> 96 </blockquote> 97 <h4 class="mansect"><a name="tag_20_93_05" id="tag_20_93_05"></a>OPERANDS</h4> 98 <blockquote> 99 <p>The following operand shall be supported:</p> 100 <dl compact> 101 <dd></dd> 102 <dt><i>pathname</i></dt> 103 <dd>A pathname to be checked.</dd> 104 </dl> 105 </blockquote> 106 <h4 class="mansect"><a name="tag_20_93_06" id="tag_20_93_06"></a>STDIN</h4> 107 <blockquote> 108 <p>Not used.</p> 109 </blockquote> 110 <h4 class="mansect"><a name="tag_20_93_07" id="tag_20_93_07"></a>INPUT FILES</h4> 111 <blockquote> 112 <p>None.</p> 113 </blockquote> 114 <h4 class="mansect"><a name="tag_20_93_08" id="tag_20_93_08"></a>ENVIRONMENT VARIABLES</h4> 115 <blockquote> 116 <p>The following environment variables shall affect the execution of <i>pathchk</i>:</p> 117 <dl compact> 118 <dd></dd> 119 <dt><i>LANG</i></dt> 120 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 121 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> the precedence of internationalization 122 variables used to determine the values of locale categories.)</dd> 123 <dt><i>LC_ALL</i></dt> 124 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 125 <dt><i>LC_CTYPE</i></dt> 126 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 127 opposed to multi-byte characters in arguments).</dd> 128 <dt><i>LC_MESSAGES</i></dt> 129 <dd><br> 130 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd> 131 <dt><i>NLSPATH</i></dt> 132 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 133 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 134 "0"></dd> 135 </dl> 136 </blockquote> 137 <h4 class="mansect"><a name="tag_20_93_09" id="tag_20_93_09"></a>ASYNCHRONOUS EVENTS</h4> 138 <blockquote> 139 <p>Default.</p> 140 </blockquote> 141 <h4 class="mansect"><a name="tag_20_93_10" id="tag_20_93_10"></a>STDOUT</h4> 142 <blockquote> 143 <p>Not used.</p> 144 </blockquote> 145 <h4 class="mansect"><a name="tag_20_93_11" id="tag_20_93_11"></a>STDERR</h4> 146 <blockquote> 147 <p>The standard error shall be used only for diagnostic messages.</p> 148 </blockquote> 149 <h4 class="mansect"><a name="tag_20_93_12" id="tag_20_93_12"></a>OUTPUT FILES</h4> 150 <blockquote> 151 <p>None.</p> 152 </blockquote> 153 <h4 class="mansect"><a name="tag_20_93_13" id="tag_20_93_13"></a>EXTENDED DESCRIPTION</h4> 154 <blockquote> 155 <p>None.</p> 156 </blockquote> 157 <h4 class="mansect"><a name="tag_20_93_14" id="tag_20_93_14"></a>EXIT STATUS</h4> 158 <blockquote> 159 <p>The following exit values shall be returned:</p> 160 <dl compact> 161 <dd></dd> 162 <dt> 0</dt> 163 <dd>All <i>pathname</i> operands passed all of the checks.</dd> 164 <dt>>0</dt> 165 <dd>An error occurred.</dd> 166 </dl> 167 </blockquote> 168 <h4 class="mansect"><a name="tag_20_93_15" id="tag_20_93_15"></a>CONSEQUENCES OF ERRORS</h4> 169 <blockquote> 170 <p>Default.</p> 171 </blockquote> 172 <hr> 173 <div class="box"><em>The following sections are informative.</em></div> 174 <h4 class="mansect"><a name="tag_20_93_16" id="tag_20_93_16"></a>APPLICATION USAGE</h4> 175 <blockquote> 176 <p>The <a href="../utilities/test.html"><i>test</i></a> utility can be used to determine whether a given pathname names an existing 177 file; it does not, however, give any indication of whether or not any component of the pathname was truncated in a directory where 178 the _POSIX_NO_TRUNC feature is not in effect. The <i>pathchk</i> utility does not check for file existence; it performs checks to 179 determine whether a pathname does exist or could be created with no pathname component truncation.</p> 180 <p>The <i>noclobber</i> option in the shell (see the <a href="../utilities/V3_chap02.html#tag_19_26"><i>set</i></a> special 181 built-in) can be used to atomically create a file. As with all file creation semantics in the System Interfaces volume of 182 POSIX.1-2024, it guarantees atomic creation, but still depends on applications to agree on conventions and cooperate on the use of 183 files after they have been created.</p> 184 <p>To verify that a pathname meets the requirements of filename portability, applications should use both the <b>-p</b> and 185 <b>-P</b> options together.</p> 186 </blockquote> 187 <h4 class="mansect"><a name="tag_20_93_17" id="tag_20_93_17"></a>EXAMPLES</h4> 188 <blockquote> 189 <p>To verify that all pathnames in an imported data interchange archive are legitimate and unambiguous on the current system:</p> 190 <pre> 191 <tt># This example assumes that no pathnames in the archive 192 # contain <newline> characters. 193 pax -f archive | sed -e 's/[^[:alnum:]]/\\&/g' | xargs pathchk -- 194 if [ $? -eq 0 ] 195 then 196 pax -r -f archive 197 else 198 echo Investigate problems before importing files. 199 exit 1 200 fi 201 </tt></pre> 202 <p>To verify that all files in the current directory hierarchy could be moved to any system conforming to the System Interfaces 203 volume of POSIX.1-2024 that also supports the <a href="../utilities/pax.html"><i>pax</i></a> utility:</p> 204 <pre> 205 <tt>find . -exec pathchk -p -P {} + 206 if [ $? -eq 0 ] 207 then 208 pax -w -f ../archive . 209 else 210 echo Portable archive cannot be created. 211 exit 1 212 fi 213 </tt></pre> 214 <p>To verify that a user-supplied pathname names a readable file and that the application can create a file extending the given 215 path without truncation and without overwriting any existing file:</p> 216 <pre> 217 <tt>case $- in 218 *C*) reset="";; 219 *) reset="set +C" 220 set -C;; 221 esac 222 test -r "$path" && pathchk "$path.out" && 223 rm "$path.out" > "$path.out" 224 if [ $? -ne 0 ]; then 225 printf "%s: %s not found or %s.out fails \ 226 creation checks.\n" $0 "$path" "$path" 227 $reset # Reset the noclobber option in case a trap 228 # on EXIT depends on it. 229 exit 1 230 fi 231 $reset 232 PROCESSING < "$path" > "$path.out" 233 </tt></pre> 234 <p>The following assumptions are made in this example:</p> 235 <ol> 236 <li> 237 <p><b>PROCESSING</b> represents the code that is used by the application to use <b>$path</b> once it is verified that 238 <b>$path.out</b> works as intended.</p> 239 </li> 240 <li> 241 <p>The state of the <i>noclobber</i> option is unknown when this code is invoked and should be set on exit to the state it was in 242 when this code was invoked. (The <b>reset</b> variable is used in this example to restore the initial state.)</p> 243 </li> 244 <li> 245 <p>Note the usage of:</p> 246 <pre> 247 <tt>rm "$path.out" > "$path.out" 248 </tt></pre> 249 <ol type="a"> 250 <li> 251 <p>The <i>pathchk</i> command has already verified, at this point, that <b>$path.out</b> is not truncated.</p> 252 </li> 253 <li> 254 <p>With the <i>noclobber</i> option set, the shell verifies that <b>$path.out</b> does not already exist before invoking <a href= 255 "../utilities/rm.html"><i>rm</i></a>.</p> 256 </li> 257 <li> 258 <p>If the shell succeeded in creating <b>$path.out</b>, <a href="../utilities/rm.html"><i>rm</i></a> removes it so that the 259 application can create the file again in the <b>PROCESSING</b> step.</p> 260 </li> 261 <li> 262 <p>If the <b>PROCESSING</b> step wants the file to exist already when it is invoked, the:</p> 263 <pre> 264 <tt>rm "$path.out" > "$path.out" 265 </tt></pre> 266 <p>should be replaced with:</p> 267 <pre> 268 <tt>> "$path.out" 269 </tt></pre> 270 <p>which verifies that the file did not already exist, but leaves <b>$path.out</b> in place for use by <b>PROCESSING</b>.</p> 271 </li> 272 </ol> 273 </li> 274 </ol> 275 </blockquote> 276 <h4 class="mansect"><a name="tag_20_93_18" id="tag_20_93_18"></a>RATIONALE</h4> 277 <blockquote> 278 <p>The <i>pathchk</i> utility was new for the ISO POSIX-2:1993 standard. It, along with the <a href= 279 "../utilities/V3_chap02.html#set"><i>set</i></a> <b>-C</b>(<i>noclobber</i>) option added to the shell, replaces the <i>mktemp</i>, 280 <i>validfnam</i>, and <i>create</i> utilities that appeared in early proposals. All of these utilities were attempts to solve 281 several common problems:</p> 282 <ul> 283 <li> 284 <p>Verify the validity (for several different definitions of "valid") of a pathname supplied by a user, generated by an 285 application, or imported from an external source.</p> 286 </li> 287 <li> 288 <p>Atomically create a file.</p> 289 </li> 290 <li> 291 <p>Perform various string handling functions to generate a temporary filename.</p> 292 </li> 293 </ul> 294 <p>The <i>create</i> utility, included in an early proposal, provided checking and atomic creation in a single invocation of the 295 utility; these are orthogonal issues and need not be grouped into a single utility. Note that the <i>noclobber</i> option also 296 provides a way of creating a lock for process synchronization; since it provides an atomic <i>create</i>, there is no race between 297 a test for existence and the following creation if it did not exist.</p> 298 <p>Having a function like <a href="../functions/tmpnam.html"><i>tmpnam</i>()</a> in the ISO C standard is important in many 299 high-level languages. The shell programming language, however, has built-in string manipulation facilities, making it very easy to 300 construct temporary filenames. The names needed obviously depend on the application, but are frequently of a form similar to:</p> 301 <pre> 302 <b>$TMPDIR/</b><i>application_abbreviation</i><b>$$.</b><i>suffix</i><tt> 303 </tt></pre> 304 <p>In cases where there is likely to be contention for a given suffix, a simple shell <b>for</b> or <b>while</b> loop can be used 305 with the shell <i>noclobber</i> option to create a file without risk of collisions, as long as applications trying to use the same 306 filename name space are cooperating on the use of files after they have been created.</p> 307 <p>For historical purposes, <b>-p</b> does not check for the use of the <hyphen-minus> character as the first character in a 308 component of the pathname, or for an empty <i>pathname</i> operand.</p> 309 </blockquote> 310 <h4 class="mansect"><a name="tag_20_93_19" id="tag_20_93_19"></a>FUTURE DIRECTIONS</h4> 311 <blockquote> 312 <p>None.</p> 313 </blockquote> 314 <h4 class="mansect"><a name="tag_20_93_20" id="tag_20_93_20"></a>SEE ALSO</h4> 315 <blockquote> 316 <p><a href="../utilities/V3_chap02.html#tag_19_07"><i>2.7 Redirection</i></a> , <a href= 317 "../utilities/V3_chap02.html#tag_19_26"><i>set</i></a> , <a href="../utilities/test.html#"><i>test</i></a></p> 318 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href= 319 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a> , <a href= 320 "../basedefs/limits.h.html"><i><limits.h></i></a></p> 321 </blockquote> 322 <h4 class="mansect"><a name="tag_20_93_21" id="tag_20_93_21"></a>CHANGE HISTORY</h4> 323 <blockquote> 324 <p>First released in Issue 4.</p> 325 </blockquote> 326 <h4 class="mansect"><a name="tag_20_93_22" id="tag_20_93_22"></a>Issue 7</h4> 327 <blockquote> 328 <p>Austin Group Interpretations 1003.1-2001 #039, #040, and #094 are applied.</p> 329 <p>SD5-XCU-ERN-121 is applied, updating the EXAMPLES section.</p> 330 <p>POSIX.1-2008, Technical Corrigendum 1, XCU/TC1-2008/0127 [291] is applied.</p> 331 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0150 [584] and XCU/TC2-2008/0151 [584] are applied.</p> 332 </blockquote> 333 <h4 class="mansect"><a name="tag_20_93_23" id="tag_20_93_23"></a>Issue 8</h4> 334 <blockquote> 335 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 336 </blockquote> 337 <div class="box"><em>End of informative text.</em></div> 338 <hr> 339 <p> </p> 340 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 341 <hr size="2" noshade> 342 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 343 POSIX™ is a Trademark of The IEEE.<br> 344 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 345 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 346 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 347 ]</font></center> 348 <hr size="2" noshade> 349 <div class="NAVHEADER"> 350 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 351 <tr class="nav"> 352 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/patch.html" accesskey="P"><<< 353 Previous</a></td> 354 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 355 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/pax.html" accesskey="N">Next >>></a></td> 356 </tr> 357 </table> 358 <hr align="left" width="100%"></div> 359 </body> 360 </html>