aboutsummaryrefslogtreecommitdiff
path: root/programs/util.h
diff options
context:
space:
mode:
authorAllan Jude <allanjude@FreeBSD.org>2023-01-25 01:20:16 +0000
committerAllan Jude <allanjude@FreeBSD.org>2023-01-25 01:20:16 +0000
commitb3392d84da5bf2162baf937c77e0557f3fd8a52b (patch)
treed9bfa8081b46f82d07e21f8ff8e70627a2aec35f /programs/util.h
parentf6ae97673c28bdb9ae795bd235ab6f26f2536a2d (diff)
Diffstat (limited to 'programs/util.h')
-rw-r--r--programs/util.h39
1 files changed, 36 insertions, 3 deletions
diff --git a/programs/util.h b/programs/util.h
index 25fa3f53aab4..add165d57ce9 100644
--- a/programs/util.h
+++ b/programs/util.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016-2020, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
+ * Copyright (c) Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under both the BSD-style license (found in the
@@ -64,7 +64,7 @@ extern "C" {
# define SET_REALTIME_PRIORITY /* disabled */
# endif
-#else /* unknown non-unix operating systen */
+#else /* unknown non-unix operating system */
# define UTIL_sleep(s) /* disabled */
# define UTIL_sleepMilli(milli) /* disabled */
# define SET_REALTIME_PRIORITY /* disabled */
@@ -122,6 +122,7 @@ int UTIL_requireUserConfirmation(const char* prompt, const char* abortMsg, const
#define STRDUP(s) strdup(s)
#endif
+
/**
* Calls platform's equivalent of stat() on filename and writes info to statbuf.
* Returns success (1) or failure (0).
@@ -135,6 +136,14 @@ int UTIL_stat(const char* filename, stat_t* statbuf);
*/
int UTIL_setFileStat(const char* filename, const stat_t* statbuf);
+/**
+ * Set atime to now and mtime to the st_mtim in statbuf.
+ *
+ * Directly wraps utime() or utimensat(). Returns -1 on error.
+ * Does not validate filename is valid.
+ */
+int UTIL_utime(const char* filename, const stat_t *statbuf);
+
/*
* These helpers operate on a pre-populated stat_t, i.e., the result of
* calling one of the above functions.
@@ -143,6 +152,7 @@ int UTIL_setFileStat(const char* filename, const stat_t* statbuf);
int UTIL_isRegularFileStat(const stat_t* statbuf);
int UTIL_isDirectoryStat(const stat_t* statbuf);
int UTIL_isFIFOStat(const stat_t* statbuf);
+int UTIL_isBlockDevStat(const stat_t* statbuf);
U64 UTIL_getFileSizeStat(const stat_t* statbuf);
/**
@@ -169,6 +179,23 @@ int UTIL_isFIFO(const char* infilename);
U64 UTIL_getFileSize(const char* infilename);
U64 UTIL_getTotalFileSize(const char* const * fileNamesTable, unsigned nbFiles);
+/**
+ * Take @size in bytes,
+ * prepare the components to pretty-print it in a scaled way.
+ * The components in the returned struct should be passed in
+ * precision, value, suffix order to a "%.*f%s" format string.
+ * Output policy is sensible to @g_utilDisplayLevel,
+ * for verbose mode (@g_utilDisplayLevel >= 4),
+ * does not scale down.
+ */
+typedef struct {
+ double value;
+ int precision;
+ const char* suffix;
+} UTIL_HumanReadableSize_t;
+
+UTIL_HumanReadableSize_t UTIL_makeHumanReadableSize(U64 size);
+
int UTIL_compareStr(const void *p1, const void *p2);
const char* UTIL_getFileExtension(const char* infilename);
void UTIL_mirrorSourceFilesDirectories(const char** fileNamesTable, unsigned int nbFiles, const char *outDirName);
@@ -272,15 +299,21 @@ void UTIL_refFilename(FileNamesTable* fnt, const char* filename);
* or NULL in case of error
*/
FileNamesTable*
-UTIL_createExpandedFNT(const char** filenames, size_t nbFilenames, int followLinks);
+UTIL_createExpandedFNT(const char* const* filenames, size_t nbFilenames, int followLinks);
+#if defined(_WIN32) || defined(WIN32)
+DWORD CountSetBits(ULONG_PTR bitMask);
+#endif
/*-****************************************
* System
******************************************/
+int UTIL_countCores(int logical);
+
int UTIL_countPhysicalCores(void);
+int UTIL_countLogicalCores(void);
#if defined (__cplusplus)
}