mirror of
https://github.com/fluencelabs/musl
synced 2025-04-26 15:52:13 +00:00
putgrent: Stop writing output on first failure
This way, if an fprintf fails, we get an incomplete group entry rather than a corrupted one.
This commit is contained in:
parent
b300d5b7bd
commit
a3b98a11a9
@ -6,9 +6,10 @@ int putgrent(const struct group *gr, FILE *f)
|
|||||||
int r;
|
int r;
|
||||||
size_t i;
|
size_t i;
|
||||||
flockfile(f);
|
flockfile(f);
|
||||||
r = fprintf(f, "%s:%s:%d:", gr->gr_name, gr->gr_passwd, gr->gr_gid);
|
if ((r = fprintf(f, "%s:%s:%d:", gr->gr_name, gr->gr_passwd, gr->gr_gid))<0) goto done;
|
||||||
if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++)
|
if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++)
|
||||||
if (fprintf(f, "%s%s", i?",":"", gr->gr_mem[i])<0) r = -1;
|
if ((r = fprintf(f, "%s%s", i?",":"", gr->gr_mem[i]))<0) goto done;
|
||||||
|
done:
|
||||||
funlockfile(f);
|
funlockfile(f);
|
||||||
return r<0 ? -1 : 0;
|
return r<0 ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user