欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 运维知识 > linux >内容正文

linux

linux cat 进程,Linux下CAT程序的C实现

发布时间:2024/4/13 linux 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 linux cat 进程,Linux下CAT程序的C实现 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

Linux下CAT程序的C实现代码片段:

#include

#include

#include

#define BUFSIZ 1024

void error(char *fmt, ...){

va_list args;

va_start(args, fmt);

fprintf(stderr, "error: ");

vfprintf(stderr, fmt, args);

fprintf(stderr, "\n");

va_end(args);

exit(1);

}

#include "syscalls.h"

main(int argc, char *argv[]){

char buf[BUFSIZ];

int n, f1;

if(argc == 1){

while((n = read(0, buf, BUFSIZ)) > 0){

write(1, buf, n);

}

}

else if(argc == 2){

if((f1 = open(argv[1], O_RDONLY, 0)) == -1){

error("cat: No such file or directory %s", argv[1]);

}else {

while((n = read(f1, buf, BUFSIZ)) > 0){

write(1, buf, n);

}

}

} else {

error("Wait for new version --javawebzwp@gmail.com");

}

}

总结

以上是生活随笔为你收集整理的linux cat 进程,Linux下CAT程序的C实现的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。