不使用 printf的时候用
#include <unistd.h>
#include <fcntl.h>
static void pnp_log(const char *s)
{
int fd,size;
fd=open("/tmp/pnp_check",O_WRONLY|O_APPEND|O_CREAT);
write(fd,s,strlen(s)+1);
write(fd," \n",2);
close(fd);
}
只留文件名
static char * (char const *path)
{
char *s = strrchr(path, '/');
if(s==NULL) {
return strdup(path);
} else {
return strdup(s + 1);
}
}
本文介绍了一个简单的C语言程序,该程序实现了一个日志记录功能,将指定字符串写入到临时目录下的文件中,并提供了一个函数用于从完整的文件路径中提取文件名部分。
1万+

被折叠的 条评论
为什么被折叠?



