我在网上搜了半天getline()函数,大多针对C++的,重载函数比较多,云里雾里的,而且没有实例,反正就是没有自己所需要的getline()函数。所以,自己在Linux下man了一把,并做了测试。getline()函数的功能是从文件中获取行信息,即每次读取一行信息。
因为我使用getline()函数的目的是获取本地网卡信息,即eth0的信息,从而判断启动机子时是否查了网线(本来可以从驱动里做,但应用层可以搞定,就不想多做处理了,谅解)。
//函数原型
#define _GNU_SOURCE
#include <stdio.h>
ssize_t getline(char **lineptr, size_t *n, FILE *stream);
ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE*stream);
[root@localhost for_test]# cat dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carriercompressed
lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
eth0: 53311 230 0 0 0 0 0 0 5370 33 0 0 0 0 0 0
[root@localhost for_test]# cat eth0_dev.c