1.在使用getmntent、setmntent 、endmntent这3个函数之前,先对这3个函数的功能作一个详细的介绍,在使用这3个函数得包含头文件#include<stdio.h>和#include<mntent.h>
(1)setmntent:打开文件系统描述文件的文件名,并且返回可以被使用的文件指针getmntent().
其函数原型为:
FILE * setmntent(const char * filename ,const char * type );
参数:filename 要打开的文件名字
type 表示打开文件的方式(r:只读 w:只写 r+:读写)等。
返回值:函数成功返回指向打开文件的文件指针FILE;失败返回NULL。
(2)getmntent:函数读取文件系统的下一行来自文件流的描述文件并返回指向结构的指针(即循环读取文件)
其函数原型:
struct mntent * getmntent(FILE * fp );
参数:fp setmntent函数中返回的文件指针,即将要进行读写的文件指针。
返回值:struct mntent 结构体,后面将会详细介绍该结构体的中变量和对应的作用。
(3)endmntent:关闭流和与其相关联的文件系统描述文件。
其函数原型:
int endmntent(FILE * fp );
参数:fp