“日志清空c语言版本”的版本间的差异
跳到导航
跳到搜索
(创建页面,内容为“=wipelog.c= <pre> #include<stdio.h> #include <stdlib.h> int main() { FILE *fp; if ((fp=fopen("/opt/mycat/logs/wrapper.log","r")) == NULL) /…”) |
|||
(未显示同一用户的2个中间版本) | |||
第1行: | 第1行: | ||
=wipelog.c= | =wipelog.c= | ||
<pre> | <pre> | ||
+ | // March 15 2022 | ||
+ | |||
+ | cat wipe.c | ||
+ | #include <stdio.h> | ||
+ | #include <string.h> | ||
+ | #include <unistd.h> | ||
+ | #include <sys/types.h> | ||
+ | #include <sys/stat.h> | ||
+ | #include <fcntl.h> | ||
+ | #include <stdlib.h> | ||
+ | #define PATHNAME "/home/evan/tmp/test" | ||
+ | |||
+ | int main(void) | ||
+ | { | ||
+ | int fd; | ||
+ | fd = open(PATHNAME,O_CREAT | O_WRONLY | O_TRUNC); | ||
+ | ftruncate(fd,0); | ||
+ | close(fd); | ||
+ | return 0; | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
#include<stdio.h> | #include<stdio.h> | ||
第9行: | 第44行: | ||
FILE *fp; | FILE *fp; | ||
if ((fp=fopen("/opt/mycat/logs/wrapper.log","r")) == NULL) | if ((fp=fopen("/opt/mycat/logs/wrapper.log","r")) == NULL) | ||
− | //if ((fp=fopen("./test.log","r")) != NULL) | + | //if ((fp=fopen("./test.log","r")) != NULL) // 如果是要清空 记得打开这行 注释上面行 |
{ | { | ||
第21行: | 第56行: | ||
</pre> | </pre> | ||
+ | [[category:ops]] [[category:c]] |
2022年3月15日 (二) 08:40的最新版本
wipelog.c
// March 15 2022 cat wipe.c #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #define PATHNAME "/home/evan/tmp/test" int main(void) { int fd; fd = open(PATHNAME,O_CREAT | O_WRONLY | O_TRUNC); ftruncate(fd,0); close(fd); return 0; } #include<stdio.h> #include <stdlib.h> int main() { FILE *fp; if ((fp=fopen("/opt/mycat/logs/wrapper.log","r")) == NULL) //if ((fp=fopen("./test.log","r")) != NULL) // 如果是要清空 记得打开这行 注释上面行 { printf("be opened.\n"); fp=fopen("/opt/mycat/logs/wrapper.log","w"); fclose(fp); //exit(1); } }