Chinaunix首页 | 论坛 | 博客
  • 博客访问: 240442
  • 博文数量: 35
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 273
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-27 23:34
个人简介

To follow the path,look to the master,follow the master.

文章分类

全部博文(35)

文章存档

2019年(1)

2018年(1)

2017年(1)

2016年(8)

2015年(24)

分类: C/C++

2015-08-02 10:51:03

fopen 打开文件
文件读写  fgetc fputc fgets fputs fread fwrite getline
fclose 关闭文件

char *strerror(int errnum)
根据errnum(错误码)打印错误信息

void perror(const char *s)
打印上一个函数运行结果,如果失败=错误信息 成功=success

int fseek(FILE *stream, long offset, int whence)
操作文件位置指针
stream:文件
offset:偏移 + -
whence:SEEK_SET(文件开始) SEEK_CUR(文件当前位置) SEEK_END(文件末尾)
int fseeko(FILE *stream, off_t offset, int whence)同fseek

ssize_t getline(char **lineptr, size_t *n, FILE *stream)

int feof(FILE *stream)

打开文件/设备文件
open
int open(const char *pathname, int flags, mode_t mode)
int open(const char *pathname, int flags)
创建/打开文件
pathname:文件名称及路径
flags:O_RDONLY O_WRONLY O_RDWR O_CREAT(如果文件不存在创建文件)
O_EXCL() O_NONBLOCK O_TRUNC
mode:权限 在文件被创建时有效
返回值:成功=int文件描述符 失败=-1

文件操作
read write
ssize_t read(int fd, void *buf, size_t count)
从文件读取数据
fd:文件描述符
buf:存放数据缓冲区
count:缓冲区大小
返回值:成功=读取字节数(>0) 0=读取文件结尾 -1=失败

ssize_t write(int fd, const void *buf, size_t count)
往文件写入数据

关闭文件
close

off_t lseek(int fd, off_t offset, int whence)

0=标准输入 1=标准输出 2=标准错误

文件描述符分配原则:当前系统最小并空闲文件描述符 实现文件输入/输出重定向

int dup2(int oldfd, int newfd)

fcntl

int stat(const char *path, struct stat *buf);
int fstat(int fd, struct stat *buf);
int lstat(const char *path, struct stat *buf);
通过文件描述符/文件名称获取文件/链接文件的属性
struct stat {
        dev_t     st_dev;     /* ID of device containing file */
        ino_t     st_ino;     /* inode number */
        mode_t    st_mode;    /*protection */
        nlink_t   st_nlink;   /*number of hard links */
        uid_t     st_uid;     /* user ID of owner */
        gid_t     st_gid;     /* group ID of owner */
        dev_t     st_rdev;    /* device ID (if special file) */
        off_t     st_size;/* total size,in bytes */
        blksize_t st_blksize;/* blocksize for file system I/O */
        blkcnt_t  st_blocks;/* number of 512B blocks allocated*/
        time_t    st_atime;/* time of last access */
        time_t    st_mtime;/* time of last modification */
        time_t    st_ctime;/* time of last status change0 */
};

mode_t umask(mode_t mask)
设置调用进程的权限屏蔽字
返回值:This system call always succeeds and the previous value of the mask is returned

int link(const char *oldpath, const char *newpath)
文件备份 只是对于文件的硬链接数加一 不能对于目录创建硬链接
int symlink(const char *oldpath, const char *newpath)
创建一个链接文件 (window:快捷方式)
oldpath:绝对路径

int unlink(const char *pathname)
删除文件
返回值:成功=0 失败=-1

目录操作:
int mkdir(const char *pathname, mode_t mode)
创建目录
pathname:名称
mode:权限
返回值:成功=0 失败=-1

int rmdir(const char *pathname)
删除空目录

DIR *opendir(const char *name)
打开目录
成功=地址 失败=NULL

struct dirent *readdir(DIR *dirp)
读取目录内容、

int closedir(DIR *dirp)

int chdir(const char *path)
改变调用进程的工作目录

/etc/shadow
struct spwd *getspnam(const char *name)
通过用户名获取/etc/shadow文件用户信息

void setspent(void);
打开/etc/shadow
struct spwd *getspent(void);
读取/etc/shadow文件内容
void endspent(void);
关闭/etc/shadow

/etc/passwd
 struct passwd *getpwnam(const char *name)

void setpwent(void);
打开/etc/passwd
struct passwd *getpwent(void);
读取/etc/passwd
void endpwent(void);
关闭/etc/passwd

char *crypt(const char *key, const char *salt)
密码名码进行加密

char *getpass( const char *prompt)
隐形接收密码

time_t time(time_t *t)

struct tm *gmtime(const time_t *timep);
秒数转换为显示时间

char *asctime(const struct tm *tm)
将结构体时间转化为字符串时间

struct tm *localtime(const time_t *timep);
转换本地时间

int getopt(int argc, char * const argv[],const char *optstring)
optind:调用getopt() argv下一个索引
阅读(1218) | 评论(0) | 转发(0) |
0

上一篇:VIM

下一篇:APUE IPC机制(一)管道

给主人留下些什么吧!~~