View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001255 | 1003.1(2016/18)/Issue7+TC2 | System Interfaces | public | 2019-06-08 12:31 | 2024-06-11 09:08 |
Reporter | stephane | Assigned To | |||
Priority | normal | Severity | Objection | Type | Enhancement Request |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Stephane Chazelas | ||||
Organization | |||||
User Reference | |||||
Section | glob(), EXAMPLES section | ||||
Page Number | 1111 (in the 2018 edition) | ||||
Line Number | 37598 | ||||
Interp Status | --- | ||||
Final Accepted Text | 0001255:0004487 | ||||
Summary | 0001255: improper shell code in glob() example | ||||
Description | Even though it is not the main point of that example, the POSIX specification should avoid showing examples of bad shell coding practice. Here, that: ls -l *.c Should be: ls -ld -- *.c As the obvious intention of that code is to list the attributes of the non-hidden files whose name ends in .c. The example does say "approximately" which leaves it unclear in which way it differs. One of the differences in functionality is when the glob doesn't match any file, which could be easily addressed by adding the GLOB_NOCHECK flag. | ||||
Desired Action | Replace all occurrences of "ls -l *.c" with "ls -ld -- *.c", "ls -l *.c *.h" with "ls -ld -- *.c *.h" Change the first example to: globbuf.gl_offs = 3; if (glob("*.c", GLOB_DOOFFS|GLOB_NOCHECK, NULL, &globbuf)) abort(); globbuf.gl_pathv[0] = "ls"; globbuf.gl_pathv[1] = "-ld"; globbuf.gl_pathv[2] = "--"; The second to: globbuf.gl_offs = 3; if (glob("*.c", GLOB_DOOFFS|GLOB_NOCHECK, NULL, &globbuf) || glob("*.h", GLOB_DOOFFS|GLOB_NOCHECK|GLOB_APPEND, NULL, &globbuf)) abort(); Possibly clarify in which way it differs or does not differ from the sh equivalent. Like state that it should result in the execution of ls with the same list of arguments. | ||||
Tags | tc3-2008 |
|
If we add GLOB_NOCHECK as suggested to reduce the difference between using glob()+execvp() and executing "ls -ld -- *.c" in the shell, then we should add GLOB_ERR as well. I don't like the half-way-house error checking that just calls abort(). We should either not add error checking (do we do it in any other example application code?) or add "proper" error checking. |
|
On page 1111 line 37598,37600 section glob(), change:ls -l *.cto: ls -ld -- *.c On page 1111 line 37609 section glob(), change: ls -l *.c *.hto: ls -ld -- *.c *.h On page 1111 line 37601 section glob(), change: The application could obtain approximately the same result using the sequence: to: The application could obtain the same result (except for error handling, omitted here for simplicity) using the sequence: Change the first example (lines 37603-37606) to: globbuf.gl_offs = 3; glob("*.c", GLOB_DOOFFS|GLOB_NOCHECK|GLOB_ERR, NULL, &globbuf); globbuf.gl_pathv[0] = "ls"; globbuf.gl_pathv[1] = "-ld"; globbuf.gl_pathv[2] = "--"; // to establish the initial arguments that // sh -c "ls -ld --" would produce for both examplesThe second (lines 37610-37614) to: could be simulated using GLOB_APPEND as follows: globbuf.gl_offs = 3; glob("*.c", GLOB_DOOFFS|GLOB_NOCHECK|GLOB_ERR, NULL, &globbuf); glob("*.h", GLOB_DOOFFS|GLOB_NOCHECK|GLOB_ERR|GLOB_APPEND, NULL, &globbuf); ... |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-06-08 12:31 | stephane | New Issue | |
2019-06-08 12:31 | stephane | Name | => Stephane Chazelas |
2019-06-08 12:31 | stephane | Section | => glob(), EXAMPLES section |
2019-06-08 12:31 | stephane | Page Number | => 1111 (in the 2018 edition) |
2019-06-08 12:31 | stephane | Line Number | => 37598 |
2019-07-18 12:08 | geoffclare | Note Added: 0004486 | |
2019-07-18 16:18 | geoffclare | Note Added: 0004487 | |
2019-07-18 16:18 | geoffclare | Note Edited: 0004487 | |
2019-07-18 16:19 | geoffclare | Interp Status | => --- |
2019-07-18 16:19 | geoffclare | Final Accepted Text | => 0000529:0001255 |
2019-07-18 16:19 | geoffclare | Status | New => Resolved |
2019-07-18 16:19 | geoffclare | Resolution | Open => Accepted As Marked |
2019-07-18 16:20 | geoffclare | Final Accepted Text | 0000529:0001255 => 0001255:0004487 |
2019-07-18 16:20 | geoffclare | Tag Attached: tc3-2008 | |
2019-11-19 16:28 | geoffclare | Status | Resolved => Applied |
2024-06-11 09:08 | agadmin | Status | Applied => Closed |