我正在尝试使用 DJGPP C 编译器从 DOS 中的 C 程序获取所有可用驱动器的列表(我不是指 Windows 命令提示符,我指的是实际的 DOS 6.0)。
我找不到直接执行此操作的 API,所以我只是循环访问驱动器 A 到 Z 并尝试测试它们是否存在。我已经尝试使用 opendir
、access
和 statfs
进行此测试,但在所有 3 个中我都收到如下消息:
Insert diskette for drive B: and press any key when ready
有什么方法可以确定我是否可以完全非交互式地从驱动器读取数据?如果存在驱动器但未加载磁盘,我只想能够表现得好像该驱动器不存在并继续。
最佳答案
所以,就在发布这篇文章后不久,我发现 实际上有一个 API 可以使用 setmntent 直接做我想做的事。和 getmntent .
这是一个代码示例:
FILE *mntentptr = setmntent(NULL, NULL); // this won't segfault as DJGPP ignores both pointers
struct mntent *fsdetails;
while (fsdetails = getmntent(mntentptr)){
printf("Drive %s is present", fsdetails->mnt_dir);
}
关于c - DOS 中的非交互式驱动器列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26696039/