View Issue Details

IDProjectCategoryView StatusLast Update
00004511003.1(2008)/Issue 7System Interfacespublic2013-04-16 13:06
Reportergeoffclare Assigned Toajosey  
PrioritynormalSeverityCommentTypeError
Status ClosedResolutionAccepted 
NameGeoff Clare
OrganizationThe Open Group
User Reference
Sectionfprintf
Page Number902
Line Number30140
Interp Status---
Final Accepted TextSee desired action.
Summary0000451: PATH_MAX and getpid() problems in fprintf() example
DescriptionThe 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 ActionChange:

    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());
        ...
    }
Tagstc1-2008

Activities

There are no notes attached to this issue.

Issue History

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