summaryrefslogtreecommitdiffstats
path: root/pcitool
diff options
context:
space:
mode:
Diffstat (limited to 'pcitool')
-rw-r--r--pcitool/CMakeLists.txt8
-rw-r--r--pcitool/formaters.c47
-rw-r--r--pcitool/formaters.h12
-rw-r--r--pcitool/sysinfo.c172
-rw-r--r--pcitool/sysinfo.h7
5 files changed, 0 insertions, 246 deletions
diff --git a/pcitool/CMakeLists.txt b/pcitool/CMakeLists.txt
deleted file mode 100644
index 6dc7942..0000000
--- a/pcitool/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-include_directories(
- ${CMAKE_SOURCE_DIR}
-)
-
-set(HEADERS ${HEADERS} sysinfo.h formaters.h)
-
-add_library(pcitool STATIC sysinfo.c formaters.c)
-
diff --git a/pcitool/formaters.c b/pcitool/formaters.c
deleted file mode 100644
index 91b8c77..0000000
--- a/pcitool/formaters.c
+++ /dev/null
@@ -1,47 +0,0 @@
-#include <stdio.h>
-
-void PrintTime(size_t duration) {
- if (duration > 999999999999) printf("%4.1lf""d", 1.*duration/86400000000);
- else if (duration > 99999999999) printf("%4.1lf""h", 1.*duration/3600000000);
- else if (duration > 9999999999) printf("%4.2lf""h", 1.*duration/3600000000);
- else if (duration > 999999999) printf("%4.1lf""m", 1.*duration/60000000);
- else if (duration > 99999999) printf("%4.2lf""m", 1.*duration/60000000);
- else if (duration > 9999999) printf("%4.1lf""s", 1.*duration/1000000);
- else if (duration > 999999) printf("%4.2lf""s", 1.*duration/1000000);
- else if (duration > 999) printf("%3lu""ms", duration/1000);
- else printf("%3lu""us", duration);
-}
-
-void PrintNumber(size_t num) {
- if (num > 999999999999999999) printf("%3lue", num/1000000000000000000);
- else if (num > 999999999999999) printf("%3lup", num/1000000000000000);
- else if (num > 999999999999) printf("%3lut", num/1000000000000);
- else if (num > 999999999) printf("%3lug", num/1000000000);
- else if (num > 999999) printf("%3lum", num/1000000);
- else if (num > 9999) printf("%3luk", num/1000);
- else printf("%4lu", num);
-}
-
-void PrintSize(size_t num) {
- if (num >= 112589990684263) printf("%4.1lf PB", 1.*num/1125899906842624);
- else if (num >= 109951162778) printf("%4.1lf TB", 1.*num/1099511627776);
- else if (num >= 107374183) printf("%4.1lf GB", 1.*num/1073741824);
- else if (num >= 1048576) printf("%4lu MB", num/1048576);
- else if (num >= 1024) printf("%4lu KB", num/1024);
- else printf("%5lu B", num);
-}
-
-void PrintPercent(size_t num, size_t total) {
- if (num >= total) printf(" 100");
- else printf("%4.1lf", 100.*num/total);
-
-}
-
-char *GetPrintSize(char *str, size_t size) {
- if (size >= 1073741824) sprintf(str, "%.1lf GB", 1.*size / 1073741824);
- else if (size >= 1048576) sprintf(str, "%.1lf MB", 1.*size / 1048576);
- else if (size >= 1024) sprintf(str, "%lu KB", size / 1024);
- else sprintf(str, "%lu B ", size);
-
- return str;
-}
diff --git a/pcitool/formaters.h b/pcitool/formaters.h
deleted file mode 100644
index c854da5..0000000
--- a/pcitool/formaters.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef _PCITOOL_FORMATERS_H
-#define _PCITOOL_FORMATERS_H
-
-void PrintTime(size_t duration);
-void PrintNumber(size_t num);
-void PrintSize(size_t num);
-void PrintPercent(size_t num, size_t total);
-char *GetPrintSize(char *str, size_t size);
-
-
-#endif /* _PCITOOL_FORMATERS_H */
-
diff --git a/pcitool/sysinfo.c b/pcitool/sysinfo.c
deleted file mode 100644
index d6f57fe..0000000
--- a/pcitool/sysinfo.c
+++ /dev/null
@@ -1,172 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <strings.h>
-
-#define MEMINFO_FILE "/proc/meminfo"
-#define MTAB_FILE "/etc/mtab"
-
-#define BAD_OPEN_MESSAGE \
-"Error: /proc must be mounted\n" \
-" To mount /proc at boot you need an /etc/fstab line like:\n" \
-" /proc /proc proc defaults\n" \
-" In the meantime, run \"mount /proc /proc -t proc\"\n"
-
-/* This macro opens filename only if necessary and seeks to 0 so
- * that successive calls to the functions are more efficient.
- * It also reads the current contents of the file into the global buf.
- */
-#define FILE_TO_BUF(filename) do{ \
- static int fd, local_n; \
- if ((fd = open(filename, O_RDONLY)) == -1) { \
- fputs(BAD_OPEN_MESSAGE, stderr); \
- fflush(NULL); \
- _exit(102); \
- } \
- lseek(fd, 0L, SEEK_SET); \
- if ((local_n = read(fd, buf, sizeof buf - 1)) < 0) { \
- perror(filename); \
- fflush(NULL); \
- _exit(103); \
- } \
- buf[local_n] = '\0'; \
- close(fd); \
-}while(0)
-
-
-typedef struct mem_table_struct {
- const char *name; /* memory type name */
- unsigned long *slot; /* slot in return struct */
-} mem_table_struct;
-
-static int compare_mem_table_structs(const void *a, const void *b){
- return strcmp(((const mem_table_struct*)a)->name,((const mem_table_struct*)b)->name);
-}
-
-size_t get_free_memory(void){
- char buf[4096];
- unsigned long kb_main_buffers, kb_main_cached, kb_main_free;
- char namebuf[16]; /* big enough to hold any row name */
- mem_table_struct findme = { namebuf, NULL};
- mem_table_struct *found;
- char *head;
- char *tail;
-
- const mem_table_struct mem_table[] = {
- {"Buffers", &kb_main_buffers}, // important
- {"Cached", &kb_main_cached}, // important
- {"MemFree", &kb_main_free}, // important
- };
- const int mem_table_count = sizeof(mem_table)/sizeof(mem_table_struct);
-
- FILE_TO_BUF(MEMINFO_FILE);
-
- head = buf;
- for(;;){
- tail = strchr(head, ':');
- if(!tail) break;
- *tail = '\0';
- if(strlen(head) >= sizeof(namebuf)){
- head = tail+1;
- goto nextline;
- }
- strcpy(namebuf,head);
- found = bsearch(&findme, mem_table, mem_table_count,
- sizeof(mem_table_struct), compare_mem_table_structs
- );
- head = tail+1;
- if(!found) goto nextline;
- *(found->slot) = strtoul(head,&tail,10);
-nextline:
- tail = strchr(head, '\n');
- if(!tail) break;
- head = tail+1;
- }
-
- return (kb_main_buffers + kb_main_cached + kb_main_free) * 1024;
-}
-
-
-int get_file_fs(const char *fname, size_t size, char *fs) {
- int err = 0;
- char buf[4096];
- char *fn;
-
- char *head;
- char *tail;
-
- size_t len, max = 0;
- struct stat st;
-
- if ((!fname)||(!fs)||(size < 3)) return -1;
-
- if (*fname == '/') {
- fn = (char*)fname;
- } else {
- if (!getcwd(buf, 4095)) return -1;
- fn = malloc(strlen(fname) + strlen(buf) + 2);
- if (!fn) return -1;
- sprintf(fn, "%s/%s", buf, fname);
- }
-
- if (!stat(fn, &st)) {
- if (S_ISBLK(st.st_mode)) {
- strcpy(fs, "raw");
- goto clean;
- }
- }
-
- FILE_TO_BUF(MTAB_FILE);
-
- head = buf;
- for(;;){
- head = strchr(head, ' ');
- if(!head) break;
-
- head += 1;
- tail = strchr(head, ' ');
- if(!tail) break;
-
- *tail = '\0';
-
- len = strlen(head);
- if((len <= max)||(strncmp(head, fn, len))) {
- head = tail+1;
- goto nextline;
- }
-
- head = tail + 1;
- tail = strchr(head, ' ');
- if(!tail) break;
-
- *tail = '\0';
-
- if (!strncasecmp(head,"root",4)) {
- head = tail+1;
- goto nextline;
- }
-
- max = len;
-
- if (strlen(head) >= size) err = -1;
- else {
- err = 0;
- strcpy(fs, head);
- }
-
- head = tail+1;
-nextline:
- tail = strchr(head, '\n');
- if(!tail) break;
- head = tail+1;
- }
-
-clean:
- if (fn != fname) free(fn);
-
- return err;
-}
diff --git a/pcitool/sysinfo.h b/pcitool/sysinfo.h
deleted file mode 100644
index d5636a7..0000000
--- a/pcitool/sysinfo.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef _PCITOOL_SYSINFO_H
-#define _PCITOOL_SYSINFO_H
-
-size_t get_free_memory();
-int get_file_fs(const char *fname, size_t size, char *fs);
-
-#endif /* _PCITOOL_SYSINFO_H */