目录函数及常用函数

函数getpwuid  根据用户id到/etc/passwd文件下解析获得
struct passwd *getpwuid(uid_t uid);
参数: uid:用户id
返回值: 成功返回id对应用户的信息 ,失败返回NULL


函数  getgrgid 根据gid到/etc/group文件中解析组信息
struct group *getgrgid(gid_t gid);
参数: gid:组id
返回值: 成功返回组信息, 失败返回NULL

系统时间的获取:
函数  time  获得1970年到现在的秒数
time_t time(time_t *t);
time_t tm;
time(&tm)        //tm = time(NULL);
参数: t:存放秒数的空间首地址
返回值:成功返回1970年到现在的秒数 ,失败返回-1

 函数  ctime  将时间秒数转化成字符串
char *ctime(const time_t *timep);     //date
参数: timep:保存时间空间的地址
返回值: 成功返回获得时间字符串的首地址, 失败返回NULL

函数 localtime  将秒数转化为日历时间

truct tm *localtime(const time_t *timep);
参数: timep:保存秒数空间的地址
返回值: 成功返回保存日历时间结构体的指针 ,失败返回NULL

日历时间从1900年一月一日00:00:00开始计算在输出时年份+1900,月份+1;

函数  symlink 创建一个链接向oldpath文件的新符号链接文件    //软链接,类似快捷方式
int  symlink(const  char  *oldpath, const char *newpath);
参数: oldpath:被链接向的文件的路径, newpath:新符号链接文件
返回值: 成功返回0 ,失败返回-1

 函数  remove  删除一个文件
int remove(const char *pathname);
参数: pathname:删除文件的路径
返回值: 成功返回0 ,失败返回-1

函数  rename    改文件名  //mv rename
int  rename(const  char  *oldpath,  const char *newpath);
参数: oldpath:老文件名 ,newpath:新文件名
返回值: 成功返回0 ,失败返回-1

函数  link  创建硬链接文件,两个文件关联一个存储地址,不能链目录,一个被删另一个无影响             //   ln 1 2 
int  link(const char *oldpath, const char *newpath);
参数: oldpath:要链接向的文件 ,newpath:创建的新硬链接文件
返回值: 成功返回0 ,失败返回-1

函数 truncate  改变文件大小

int truncate(const char *path,off_t length)

path目标文件,length想要的文件空间大小

报错函数

1.perror
void perror(const char *s);-->strerror()  封装了函数strerror
功能: 打印s字符串和errno对应的错误信息
参数: s:要打印在终端上的出错信息

2.strerror
char *strerror(int errnum);
功能: 打印errnum出错码对应的出错信息
参数: errnum:出错errno号
返回值:成功返回对应的错误信息

否则ruturn 1;

0为成功其他为对应的出错信息

3.error ===>>>exit();
void error(int status, int errnum, const char *format, ...);
功能:
程序出错打印对应出错原因和用户输入字符串并退出
参数:
status:程序退出的状态
 EXIT_FAILURE    1  
 EXIT_SUCCESS    0   
errnum:错误码

Makefile 编写 工程管理工具

vim 编辑器,gcc 编译器 ,gdb 调试器 make

第一行冒号左边为 目标 右边为依赖

$^代替目标,$@代替依赖

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值