Add set/get/endfsent() support for musl libc

This patch adds support for the following /etc/fstab API's on systems
that do not have them, e.g. musl libc on Alpine Linux.

- setfsent()
- getfsent(), and
- endfsent()

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-08-02 00:50:23 +02:00
1 parent 7eac88b639
commit c38b452ac4
4 files changed
+59 -1

No files matched your search

+39
View File
@@ -254,6 +254,45 @@ void set_hostname(char **hostname)
sethostname(*hostname, strlen(*hostname));
}
#ifndef HAVE_GETFSENT
static lfile_t *fstab = NULL;
int setfsent(void)
{
if (fstab)
lfclose(fstab);
fstab = lfopen("/etc/fstab", " \t\n");
if (!fstab)
return 0;
return 1;
}
struct fstab *getfsent(void)
{
static struct fstab fs;
fs.fs_spec = lftok(fstab);
fs.fs_file = lftok(fstab);
fs.fs_vfstype = lftok(fstab);
fs.fs_mntops = lftok(fstab);
fs.fs_type = (const char *)lftok(fstab);
fs.fs_freq = atoi(lftok(fstab) ?: 0);
fs.fs_passno = atoi(lftok(fstab) ?: 0);
return &fs;
}
void endfsent(void)
{
if (fstab)
lfclose(fstab);
fstab = NULL;
}
#endif /* HAVE_GETFSENT */
/**
* Local Variables:
* indent-tabs-mode: t