[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r2720 - in GNUnet: . src/include src/util
From: |
grothoff |
Subject: |
[GNUnet-SVN] r2720 - in GNUnet: . src/include src/util |
Date: |
Wed, 3 May 2006 13:00:16 -0700 (PDT) |
Author: grothoff
Date: 2006-05-03 13:00:11 -0700 (Wed, 03 May 2006)
New Revision: 2720
Modified:
GNUnet/configure.ac
GNUnet/src/include/gnunet_util.h
GNUnet/src/util/string.c
Log:
human readable
Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2006-05-03 08:42:17 UTC (rev 2719)
+++ GNUnet/configure.ac 2006-05-03 20:00:11 UTC (rev 2720)
@@ -178,7 +178,6 @@
AC_CHECK_LIB([kvm],[kvm_open])
AC_CHECK_LIB([kstat],[kstat_open])
-
# test for libextractor
extractor=0
AC_MSG_CHECKING(for libextractor)
Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h 2006-05-03 08:42:17 UTC (rev 2719)
+++ GNUnet/src/include/gnunet_util.h 2006-05-03 20:00:11 UTC (rev 2720)
@@ -2504,6 +2504,12 @@
#endif
/**
+ * @brief Get human-readable filesizes from byte numbers
+ * @param size_n the size in bytes
+ */
+char * getHumanSize (unsigned long long int size_n);
+
+/**
* @brief Enumerate all network interfaces
* @param callback the callback function
*/
Modified: GNUnet/src/util/string.c
===================================================================
--- GNUnet/src/util/string.c 2006-05-03 08:42:17 UTC (rev 2719)
+++ GNUnet/src/util/string.c 2006-05-03 20:00:11 UTC (rev 2720)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2005 Christian Grothoff (and other contributing authors)
+ (C) 2005, 2006 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -90,4 +90,38 @@
}
#endif
+#define KIBIBYTE_SIZE 1024L
+#define MEBIBYTE_SIZE 1048576L
+#define GIBIBYTE_SIZE 1073741824L
+
+/**
+ * Method to get human-readable filesizes from byte numbers.
+ */
+char * getHumanSize (unsigned long long int size_n)
+{
+ unsigned long long size_d;
+ char * size;
+ char * ret;
+
+ size = MALLOC(128);
+ if (size_n == 0) {
+ strcpy(size, _("unknown")); }
+ else if (size_n / 4> GIBIBYTE_SIZE) {
+ size_d = size_n / GIBIBYTE_SIZE;
+ SNPRINTF(size, 128, "%llu %s", size_d, _("GiB")); }
+ else if (size_n / 4> MEBIBYTE_SIZE) {
+ size_d = size_n / MEBIBYTE_SIZE;
+ SNPRINTF(size, 128, "%llu %s", size_d, _("MiB")); }
+ else if (size_n / 4> KIBIBYTE_SIZE) {
+ size_d = size_n / KIBIBYTE_SIZE;
+ SNPRINTF(size, 128, "%llu %s", size_d, _("KiB")); }
+ else {
+ size_d = size_n;
+ SNPRINTF(size, 128, "%llu %s", size_d, _("Bytes")); }
+ ret = STRDUP(size);
+ FREE(size);
+ return ret;
+}
+
+
/* end of string.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r2720 - in GNUnet: . src/include src/util,
grothoff <=