* Copyright 2015 Mellanox Technologies, Ltd
*/
+#include <fcntl.h>
#include <inttypes.h>
#include <linux/sockios.h>
#include <linux/ethtool.h>
#include <stdint.h>
#include <stdio.h>
+#include <unistd.h>
#include <rte_ethdev_driver.h>
#include <rte_common.h>
static inline int
mlx5_read_ib_stat(struct mlx5_priv *priv, const char *ctr_name, uint64_t *stat)
{
- FILE *file;
+ int fd;
+
if (priv->sh) {
MKSTR(path, "%s/ports/%d/hw_counters/%s",
priv->sh->ibdev_path,
priv->ibv_port,
ctr_name);
-
- file = fopen(path, "rb");
- if (file) {
- int n = fscanf(file, "%" SCNu64, stat);
-
- fclose(file);
- if (n == 1)
+ fd = open(path, O_RDONLY);
+ if (fd != -1) {
+ char buf[21] = {'\0'};
+ ssize_t n = read(fd, buf, sizeof(buf));
+
+ close(fd);
+ if (n != -1) {
+ *stat = strtoull(buf, NULL, 10);
return 0;
+ }
}
}
*stat = 0;