]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-compat-util.h
test-ref-store: remove force-create argument for create-reflog
[thirdparty/git.git] / git-compat-util.h
index 141bb86351e63cba6f5c92e5badfba7c78a5eb9f..c6bd2a84e55363d282f56296d81dd0a3d56b5762 100644 (file)
 #define unsigned_mult_overflows(a, b) \
     ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))
 
+/*
+ * Returns true if the left shift of "a" by "shift" bits will
+ * overflow. The type of "a" must be unsigned.
+ */
+#define unsigned_left_shift_overflows(a, shift) \
+    ((shift) < bitsizeof(a) && \
+     (a) > maximum_unsigned_value_of_type(a) >> (shift))
+
 #ifdef __GNUC__
 #define TYPEOF(x) (__typeof__(x))
 #else
@@ -729,7 +737,7 @@ char *gitmkdtemp(char *);
 
 #ifdef NO_UNSETENV
 #define unsetenv gitunsetenv
-void gitunsetenv(const char *);
+int gitunsetenv(const char *);
 #endif
 
 #ifdef NO_STRCASESTR
@@ -862,6 +870,23 @@ static inline size_t st_sub(size_t a, size_t b)
        return a - b;
 }
 
+static inline size_t st_left_shift(size_t a, unsigned shift)
+{
+       if (unsigned_left_shift_overflows(a, shift))
+               die("size_t overflow: %"PRIuMAX" << %u",
+                   (uintmax_t)a, shift);
+       return a << shift;
+}
+
+static inline unsigned long cast_size_t_to_ulong(size_t a)
+{
+       if (a != (unsigned long)a)
+               die("object too large to read on this platform: %"
+                   PRIuMAX" is cut off to %lu",
+                   (uintmax_t)a, (unsigned long)a);
+       return (unsigned long)a;
+}
+
 #ifdef HAVE_ALLOCA_H
 # include <alloca.h>
 # define xalloca(size)      (alloca(size))
@@ -879,7 +904,6 @@ char *xstrndup(const char *str, size_t len);
 void *xrealloc(void *ptr, size_t size);
 void *xcalloc(size_t nmemb, size_t size);
 void xsetenv(const char *name, const char *value, int overwrite);
-void xunsetenv(const char *name);
 void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
 const char *mmap_os_err(void);
 void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);