From 54273d1042b7a7e9a5635ccf15363eec819cb951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 12 Nov 2020 13:20:19 +0100 Subject: [PATCH] csum-file: add hashwrite_be64() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a helper function for hashing and writing 64-bit integers in network byte order. It returns the number of written bytes. This simplifies callers that keep track of the file offset, even though this number is a constant. Suggested-by: Derrick Stolee Original-patch-by: Taylor Blau Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano --- csum-file.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/csum-file.h b/csum-file.h index f9cbd317fb..e54d53d1d0 100644 --- a/csum-file.h +++ b/csum-file.h @@ -62,4 +62,11 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data) hashwrite(f, &data, sizeof(data)); } +static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data) +{ + data = htonll(data); + hashwrite(f, &data, sizeof(data)); + return sizeof(data); +} + #endif