31 lines
663 B
C
31 lines
663 B
C
/*
|
|
* test.c
|
|
* Copyright (C) 2021 light <light@lightdeMBP>
|
|
*
|
|
* Distributed under terms of the MIT license.
|
|
*/
|
|
|
|
#include "./include/test.h"
|
|
#include<stdio.h>
|
|
#define MAX_LINE 1024
|
|
|
|
double get_sqrt(double var1)
|
|
{
|
|
return sqrt(var1);
|
|
}
|
|
|
|
void updateMem(unsigned int *all, unsigned int *fre, float *useage) {
|
|
char buf[MAX_LINE]; /*缓冲区*/
|
|
FILE *fp; /*文件指针*/
|
|
if((fp = fopen("./meminfo","r")) == NULL)
|
|
{
|
|
perror("fail to read");
|
|
return;
|
|
}
|
|
fgets(buf,MAX_LINE,fp);
|
|
sscanf(buf, "%*s %u kB",all);
|
|
fgets(buf,MAX_LINE,fp);
|
|
sscanf(buf, "%*s %u kB",fre);
|
|
*useage = 1 - (float) *fre / *all;
|
|
}
|