View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0000451 | 1003.1(2008)/Issue 7 | System Interfaces | public | 2011-05-23 14:43 | 2013-04-16 13:06 |
| Reporter | geoffclare | Assigned To | ajosey | ||
| Priority | normal | Severity | Comment | Type | Error |
| Status | Closed | Resolution | Accepted | ||
| Name | Geoff Clare | ||||
| Organization | The Open Group | ||||
| User Reference | |||||
| Section | fprintf | ||||
| Page Number | 902 | ||||
| Line Number | 30140 | ||||
| Interp Status | --- | ||||
| Final Accepted Text | See desired action. | ||||
| Summary | 0000451: PATH_MAX and getpid() problems in fprintf() example | ||||
| Description | The fprintf "Creating a Filename" example assumes that PATH_MAX is defined as a compile-time constant, and that getpid() returns an int. (It also assumes that the created pathname cannot be longer than PATH_MAX, although that is probably a safe assumption for this specific case involving a user's home directory.) Note that the proposed changes incorporate the change from "filename" to "pathname" in 0000291. | ||||
| Desired Action | Change: Creating a Filename The following example creates a filename using information from a previous getpwnam() function that returned the HOME directory of the user. #include <stdio.h> #include <sys/types.h> #include <unistd.h> ... char filename[PATH_MAX+1]; struct passwd *pw; ... sprintf(filename, "%s/%d.out", pw->pw_dir, getpid()); ... to: Creating a Pathname The following example creates a pathname using information from a previous getpwnam() function that returned the password database entry of the user. #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <unistd.h> ... char *pathname; struct passwd *pw; size_t len; ... // digits required for pid_t is number of bits times log2(10) = approx 10/33 len = strlen(pw->pw_dir) + 1 + 1+(sizeof(pid_t)*80+32)/33 + sizeof ".out"; pathname = malloc(len); if (pathname != NULL) { snprintf(pathname, len, "%s/%jd.out", pw->pw_dir, (intmax_t)getpid()); ... } | ||||
| Tags | tc1-2008 | ||||
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2011-05-23 14:43 | geoffclare | New Issue | |
| 2011-05-23 14:43 | geoffclare | Status | New => Under Review |
| 2011-05-23 14:43 | geoffclare | Assigned To | => ajosey |
| 2011-05-23 14:43 | geoffclare | Name | => Geoff Clare |
| 2011-05-23 14:43 | geoffclare | Organization | => The Open Group |
| 2011-05-23 14:43 | geoffclare | Section | => fprintf |
| 2011-05-23 14:43 | geoffclare | Page Number | => 902 |
| 2011-05-23 14:43 | geoffclare | Line Number | => 30140 |
| 2011-05-23 14:43 | geoffclare | Interp Status | => --- |
| 2011-06-09 16:15 | geoffclare | Description Updated | |
| 2011-06-09 16:15 | geoffclare | Desired Action Updated | |
| 2011-06-09 16:17 | nick | Final Accepted Text | => See desired action. |
| 2011-06-09 16:17 | nick | Status | Under Review => Resolved |
| 2011-06-09 16:17 | nick | Resolution | Open => Accepted |
| 2011-06-09 16:17 | nick | Tag Attached: tc1-2008 | |
| 2013-04-16 13:06 | ajosey | Status | Resolved => Closed |