1 Star 0 Fork 0

dybai/ExtExc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mygetline_main.c 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
dybai 提交于 2016-05-18 15:46 . first import
/*
Copyright 2016 小新de蜡笔
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "mygetline.h"
int main (int argc, char **argv)
{
char *line = NULL;
int fd = -1;
ssize_t size = 0;
if (argc < 2) {
fprintf(stderr, "Usage: %s <filepath>\n", argv[0]);
goto e_args;
}
fd = open(argv[1], O_RDONLY);
if (fd < 0) {
perror("open()");
goto e_open;
}
while ((size = mygetline(fd, &line)) > 0) {
printf("[%03d] %s", size, line);
}
if (size < 0) {
fprintf(stderr, "ERROR: %s", strerror(-size));
goto e_mygetline;
}
mygetline_destroy(&line);
close(fd);
return 0;
e_mygetline:
mygetline_destroy(&line);
e_open:
close(fd);
e_args:
return 1;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/dybai/ExtExc.git
git@gitee.com:dybai/ExtExc.git
dybai
ExtExc
ExtExc
master

搜索帮助