我想编写一种可移植的方式来获取可用磁盘空间。在Windows上,我使用var books = [
{
name : "Javascript",
author : "David Flanagan",
genre : "learning",
price : "100"
},
{
name : "PHP",
author : "Luke Welling",
genre : "learning",
price : "120"
}
/* some more books */
];
var bookModel = function (books) {
var self = this;
var rowId;
self.books = ko.observableArray(books);
var calculate = self.totals = ko.computed(function () {
var total = 0;
for (var i = 0; i < self.books().length; i++) {
total = total + +self.books()[i].price;
}
return total.toFixed(2);
});
self.addBook = function () {
self.books.push({
name: '',
author: '',
genre: '',
price: ''
});
calculate();
};
self.removeBook = function (book) {
self.books.remove(book);
rowId = book.name;
console.log(rowId);
updateLocalStorage();
calculate();
};
function updateLocalStorage() {
var localBook = JSON.parse(localStorage['table']);
for (var i = 0; i < localBook.length; i++) {
if (localBook[i].name == rowId) {
localBook.splice(i, 1);
localStorage.setItem("table", JSON.stringify(localBook));
break;
}
}
}
self.save = function () {
localStorage.setItem("table", JSON.stringify(books));
calculate();
};
};
if (localStorage['table'] == '[]') {
localStorage.clear();
}
if (localStorage['table'] !== undefined) {
var local = JSON.parse(localStorage['table']);
var viewModel = new bookModel(local);
}
else {
var viewModel = new bookModel(books);
localStorage.setItem("table", JSON.stringify(self.books));
}
ko.applyBindings(viewModel);
,在Linux上,标题GetDiskFreeSpaceEx
包含我可以使用的函数<sys/statvfs.h>
。
我的问题是,在哪些系统上我可以假设这个标头存在。有没有我可以检查的宏?像
这样的东西statvfs64()
答案 0 :(得分:1)
通常,你会使用autotools这样的东西。如果您定义了合适的配置测试,autoconf
会创建一个config.h
标头,用于定义HAVE_STATVFS
左右的宏。
但是,由于<sys/statvfs.h>
的大量可用性,您也可以像在刚刚那样轻松地测试_MSC_VER
。