View Issue Details

IDProjectCategoryView StatusLast Update
00014091003.1(2013)/Issue7+TC1System Interfacespublic2024-06-11 08:54
Reporteralanc Assigned To 
PrioritynormalSeverityEditorialTypeEnhancement Request
Status ClosedResolutionAccepted As Marked 
NameAlan Coopersmith
Organization
User Reference
Sectionfstatat()
Page Number951
Line Number32669
Interp Status---
Final Accepted Text0001409:0005238
Summary0001409: Example code for stat() could use better function name
DescriptionThe example code for stat() currently has:

/* Print out type, permissions, and number of links. */
printf("%10.10s", sperm (statbuf.st_mode));
printf("%4d", statbuf.st_nlink);

It appears that "sperm" is supposed to be a user-provided function to
make a string representing the permission bits of the mode value, but
this isn't clear, and trying to do an internet search for "sperm" to
find if this function exists somewhere is extremely unhelpful.
Desired ActionUse a better function name for the user provided function - perhaps strmode()
that actually exists on some systems, or a clearer made-up-name such as
permission_string() or mode_to_string(). Perhaps update the comment to
note that this is a user-supplied function, not part of the standard.
Tagstc3-2008

Activities

geoffclare

2020-10-09 08:38

manager   bugnote:0005039

Last edited: 2020-10-09 08:41

The comment indicates that the type is included, so the new name should include "mode" not "perm". The name strmode() should not be used for a user-supplied function as str[a-z] is a reserved prefix for <string.h>. So I suggest either str_mode() or mode_string().

Also, the %4d is wrong because is assumes nlink_t is int (or promotes to int). That line should change to:
printf(" %4ju", (uintmax_t)statbuf.st_nlink);
The later lines that print st_gid and st_uid have the same problem.

geoffclare

2021-02-15 16:58

manager   bugnote:0005238

On C181 (TC2) page 968 lines 32917-32918 change:
printf("%10.10s", sperm (statbuf.st_mode));
printf("%4d", statbuf.st_nlink);
to:
printf("%10.10s", mode_string(statbuf.st_mode));
printf(" %4ju", (uintmax_t)statbuf.st_nlink);


On C181 (TC2) page 968 line 32923 change:
printf(" %-8d", statbuf.st_uid);
to:
printf(" %-8ju", (uintmax_t)statbuf.st_uid);


On C181 (TC2) page 968 line 32928 change:
printf(" %-8d", statbuf.st_gid);
to:
printf(" %-8ju", (uintmax_t)statbuf.st_gid);

Issue History

Date Modified Username Field Change
2020-10-08 16:48 alanc New Issue
2020-10-08 16:48 alanc Name => Alan Coopersmith
2020-10-08 16:48 alanc Section => fstatat()
2020-10-08 16:48 alanc Page Number => 951
2020-10-08 16:48 alanc Line Number => 32669
2020-10-09 08:38 geoffclare Note Added: 0005039
2020-10-09 08:41 geoffclare Note Edited: 0005039
2021-02-15 16:58 geoffclare Note Added: 0005238
2021-02-15 17:00 geoffclare Interp Status => ---
2021-02-15 17:00 geoffclare Final Accepted Text => 0001409:0005238
2021-02-15 17:00 geoffclare Status New => Resolved
2021-02-15 17:00 geoffclare Resolution Open => Accepted As Marked
2021-02-15 17:00 geoffclare Tag Attached: tc3-2008
2021-03-08 15:23 geoffclare Status Resolved => Applied
2024-06-11 08:54 agadmin Status Applied => Closed