+#include <sys/ioctl.h>
+#include <locale.h>
+#include <getopt.h>
+
+#define BUFFER_SIZE 4096
+
+typedef int64_t size_sum_t;
+
+/* Yeah, global variables! */
+
+int ignore_dotfiles = 0; /* 1 means ignore files and directories
+ starting with a dot */
+
+int forced_width = 0; /* -1 means no width limit, strictly positive
+ means limit, 0 means not active */
+
+int forced_height = 0; /* -1 means no height limit, strictly positive
+ means limit, 0 means not active */
+
+int fancy_size_display = 0; /* 1 means to use floating values with K, M and G
+ as units */
+
+int reverse_sorting = 0; /* 1 means to show the large ones first */
+
+int show_top = 0; /* 1 means to show the top of the sorted list
+ instead of the bottom */
+
+/********************************************************************/
+
+/* malloc with error checking. */
+
+void *safe_malloc(size_t n) {
+ void *p = malloc(n);
+ if (!p && n != 0) {
+ fprintf(stderr, "Can not allocate memory: %s\n", strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+ return p;
+}
+
+/********************************************************************/
+
+int ignore_entry(const char *name) {
+ return
+ strcmp(name, ".") == 0 ||
+ strcmp(name, "..") == 0 ||
+ (ignore_dotfiles && name[0] == '.');
+}