linux 文件管理相关函数介绍
来源:互联网 发布:如何在淘宝社区发帖 编辑:程序博客网 时间:2024/06/07 05:54
fileno函数:文件流(FILE*)->文件描述符
#include <stdio.h>
int main(void)
{
FILE * fp; //文件流
int fd; //文件描述符
fp=fopen("/home/yaoyin/bin/test/1.c","r");
fd=fileno(fp);
printf("fd=%d\n",fd);
fclose(fp);
return 0;
}
结果: fd=3(0 stdin 1 stdout 2 stderr 未被使用的最小的描述符=3)
扫描目录:
头文件dirent.h
DIR:结构体,用于操作目录,不可改变之
dirent:结构体,与DIR相同,可操作之
Directory entries themselves are returned in dirent structures,also declared in dirent.h,
because one should never alter the fields in the DIR structure directly.
相关函数:opendir,closedir,readdir,telldir,seekdir
DIR *opendir(const char *name);
关键函数:readdir
struct dirent *readdir( DIR * dirp)
return a pointer to a structure detailing the next directory entry in the directory stream drip.
successive calls return further directory entries.
On error,or at the end of the directory,return NULL.
当其他进程创建、删除文件的同时,使用readdir,不能保证列举出所有的文件和子目录。
//1.c
int main(int argc,char *argv[])
{
//
}
gcc 1.c -o test
./test arg1 arg2
结果:argc=3 argv指向{"test","arg1","arg2"}
- linux 文件管理相关函数介绍
- Linux文件相关函数
- 内存管理相关函数 -- Linux
- linux mutex相关函数介绍
- Linux文件管理相关命令
- Linux文件管理相关命令
- Linux文件管理相关命令
- Linux 用户管理相关文件
- Linux密码相关文件介绍
- Linux 网络接口管理相关命令介绍
- 嵌入式学习28(linux系统函数之文件、文件夹管理相关函数)
- linux文件操作相关函数
- Linux系统信号管理相关操作函数
- linux中时间相关的函数介绍
- Linux 异步IO介绍--相关函数
- 使用logrotate 管理日志文件 (Linux相关)
- Linux 文件管理的相关命令_20110421
- Linux文件和目录管理相关命令
- 在LINQ to SQL中使用Translate方法以及修改查询用SQL
- myeclipse自动生成POJO类时一直找不到java src folder--解决方案
- linq to sql 的DataContext的 ExecuteCommand()方法
- Java Web笔记 – Servlet多线程同步问题及其解决方法
- 【解决方案】qq企业邮箱用outlook能发邮件不能收邮件,错误syntax error
- linux 文件管理相关函数介绍
- Launcher
- 23种设计模式及解释(中英文对照)
- 数据库主键使用详解
- HDU 3518 Boring counting - 后缀树
- DOCBOOK TEST2
- 没有真机测试又想用,设和测试读写文件的方法(找到mac下lion的沙盒路径)
- C中的 feof() 和 EOF
- Java 访问MySQL的小例子