View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0000189 | 1003.1(2008)/Issue 7 | System Interfaces | public | 2009-11-30 18:48 | 2013-04-16 13:06 |
| Reporter | eblake | Assigned To | ajosey | ||
| Priority | normal | Severity | Editorial | Type | Error |
| Status | Closed | Resolution | Accepted As Marked | ||
| Name | Eric Blake | ||||
| Organization | NA | ||||
| User Reference | ebb.getopt | ||||
| Section | getopt | ||||
| Page Number | 1041 | ||||
| Line Number | 34874 | ||||
| Interp Status | --- | ||||
| Final Accepted Text | 0000189:0000310 | ||||
| Summary | 0000189: improved getopt example | ||||
| Description | The EXAMPLES portion of getopt has multiple issues in the sample code: Because the code uses fprintf, stderr, and exit, it should include <stdio.h> and <stdlib.h>. Because the code includes <unistd.h>, it should not need to redeclare optarg, optind, or optopt. The example appears to read the value of uninitialized automatic variables. The example calls a function bproc() without a declaration. Indentation of the case statement should be consistent. An unrecognized option can include whitespace (think "cmd '- '"), so visual indication in the error message is helpful. The second example is practically redundant with the first. Assigning a string literal to a char* is not a good practice to recommend. Meanwhile, adding a SEE ALSO cross-reference hyperlink to getopts(1) would be helpful, since the DESCRIPTION includes a normative reference (line 34849) to its behavior. | ||||
| Desired Action | At line 34866, insert these lines: #include <stdio.h> #include <stdlib.h> Replace line 34871: int bflg, aflg, errflg; with: int bflg = 0, aflg = 0, errflg = 0; Delete lines 34874 and 34875: extern char *optarg; extern int optind, optopt; Replace lines 34888-34891: else { bflg++; bproc(); } with: else bflg++; Reduce the indentation of lines 34899 by four spaces, and of lines 34900-34903 and 34905-34906 by eight spaces, to be consistent with the rest of the case statement. Additionally, change line 34906 from: "Unrecognized option: -%c\n", optopt); to: "Unrecognized option: '-%c'\n", optopt); Delete lines 34925-34955 (the entire "Checking Options and Arguments" example). Replace line 34962: char *Options = "hdbtl"; with: const char *Options = "hdbtl"; At line 34997, insert a cross-reference link to XCU getopts. | ||||
| Tags | tc1-2008 | ||||
|
|
Make the change in the Desired Action, and also at line 34964 change int dbtype, i; char c; to int dbtype, c; |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2009-11-30 18:48 | eblake | New Issue | |
| 2009-11-30 18:48 | eblake | Status | New => Under Review |
| 2009-11-30 18:48 | eblake | Assigned To | => ajosey |
| 2009-11-30 18:48 | eblake | Name | => Eric Blake |
| 2009-11-30 18:48 | eblake | Organization | => NA |
| 2009-11-30 18:48 | eblake | User Reference | => ebb.getopt |
| 2009-11-30 18:48 | eblake | Section | => getopt |
| 2009-11-30 18:48 | eblake | Page Number | => 1041 |
| 2009-11-30 18:48 | eblake | Line Number | => 34874 |
| 2009-12-01 09:39 | geoffclare | Note Added: 0000310 | |
| 2009-12-03 17:04 | geoffclare | Note Edited: 0000310 | |
| 2009-12-03 17:05 | geoffclare | Interp Status | => --- |
| 2009-12-03 17:05 | geoffclare | Final Accepted Text | => 0000189:0000310 |
| 2009-12-03 17:05 | geoffclare | Status | Under Review => Resolved |
| 2009-12-03 17:05 | geoffclare | Resolution | Open => Accepted As Marked |
| 2010-08-27 13:01 | ajosey | Tag Attached: tc1-2008 | |
| 2013-04-16 13:06 | ajosey | Status | Resolved => Closed |