swapon/off: revert the non-portable change made in 2014: use setmntent, not fopen

function                                             old     new   delta
swap_on_off_main                                     449     474     +25

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko committed 2026-10-22 06:36:05 +02:00
1 parent daf8ec40e0
commit 87e54246b6
1 file changed
+5 -2
+5 -2
View File
@@ -233,7 +233,10 @@ static int do_em_all_in_fstab(void)
{
struct mntent *m;
int err = 0;
FILE *f = xfopen_for_read("/etc/fstab"); /* poor man's setmntent */
FILE *f = setmntent("/etc/fstab", "r");
if (!f)
bb_simple_perror_msg_and_die("/etc/fstab");
while ((m = getmntent(f)) != NULL) {
if (strcmp(m->mnt_type, MNTTYPE_SWAP) == 0) {
@@ -265,7 +268,7 @@ static int do_em_all_in_fstab(void)
}
if (ENABLE_FEATURE_CLEAN_UP)
fclose(f);
endmntent(f);
return err;
}