mirror of
https://github.com/shadow-maint/shadow.git
synced 2024-12-18 06:14:46 +08:00
f45498a6c2
Documentation: - Correct the comment documenting the function: write_full() doesn't write "up to" count bytes (which is write(2)'s behavior, and exactly what this function is designed to avoid), but rather exactly count bytes (on success). - While fixing the documentation, take the time to add a man-page-like comment as in other APIs. Especially, since we'll have to document a few other changes from this patch, such as the modified return values. - Partial writes are still possible on error. It's the caller's responsibility to handle that possibility. API: - In write(2), it's useful to know how many bytes were transferred, since it can have short writes. In this API, since it either writes it all or fails, that value is useless, and callers only want to know if it succeeded or not. Thus, just return 0 or -1. Implementation: - Use `== -1` instead of `< 0` to check for write(2) syscall errors. This is wisdom from Michael Kerrisk. This convention is useful because it more explicitly tells maintainers that the only value which can lead to that path is -1. Otherwise, a maintainer of the code might be confused to think that other negative values are possible. Keep it simple. - The path under `if (res == 0)` was unreachable, since the loop condition `while (count > 0)` precludes that possibility. Remove the dead code. - Use a temporary variable of type `const char *` to avoid a cast. - Rename `res`, which just holds the result from write(2), to `w`, which more clearly shows that it's just a very-short-lived variable (by it's one-letter name), and also relates itself more to write(2). I find it more readable. - Move the definition of `w` to the top of the function. Now that the function is significantly shorter, the lifetime of the variable is clearer, and I find it more readable this way. Use: - Also use `== -1` to check errors. Cc: Christian Göttsche <cgzones@googlemail.com> Cc: Serge Hallyn <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org> |
||
---|---|---|
.. | ||
.indent.pro | ||
addgrps.c | ||
age.c | ||
agetpass.c | ||
alloc.c | ||
audit_help.c | ||
basename.c | ||
bit.c | ||
btrfs.c | ||
chkname.c | ||
chkname.h | ||
chowndir.c | ||
chowntty.c | ||
cleanup_group.c | ||
cleanup_user.c | ||
cleanup.c | ||
console.c | ||
copydir.c | ||
csrand.c | ||
date_to_str.c | ||
entry.c | ||
env.c | ||
failure.c | ||
failure.h | ||
find_new_gid.c | ||
find_new_sub_gids.c | ||
find_new_sub_uids.c | ||
find_new_uid.c | ||
freezero.c | ||
freezero.h | ||
getdate.h | ||
getdate.y | ||
getgr_nam_gid.c | ||
getrange.c | ||
gettime.c | ||
hushed.c | ||
idmapping.c | ||
idmapping.h | ||
isexpired.c | ||
limits.c | ||
list.c | ||
log.c | ||
logind.c | ||
loginprompt.c | ||
mail.c | ||
Makefile.am | ||
mempcpy.c | ||
motd.c | ||
myname.c | ||
obscure.c | ||
pam_pass_non_interactive.c | ||
pam_pass.c | ||
prefix_flag.c | ||
pwd2spwd.c | ||
pwd_init.c | ||
pwdcheck.c | ||
readpassphrase.c | ||
readpassphrase.h | ||
remove_tree.c | ||
rlogin.c | ||
root_flag.c | ||
salt.c | ||
setugid.c | ||
setupenv.c | ||
shell.c | ||
stpecpy.c | ||
stpeprintf.c | ||
strtoday.c | ||
sub.c | ||
sulog.c | ||
ttytype.c | ||
tz.c | ||
ulimit.c | ||
user_busy.c | ||
utmp.c | ||
valid.c | ||
xgetgrgid.c | ||
xgetgrnam.c | ||
xgetpwnam.c | ||
xgetpwuid.c | ||
xgetspnam.c | ||
xgetXXbyYY.c | ||
xprefix_getpwnam.c | ||
yesno.c |