t3701: avoid depending on the TTY prerequisite
[git/debian.git] / csum-file.h
bloba98b1eee53f40367ad06c7aa82da7af0ca6ed6bc
1 #ifndef CSUM_FILE_H
2 #define CSUM_FILE_H
4 #include "hash.h"
6 struct progress;
8 /* A SHA1-protected file */
9 struct hashfile {
10 int fd;
11 int check_fd;
12 unsigned int offset;
13 git_hash_ctx ctx;
14 off_t total;
15 struct progress *tp;
16 const char *name;
17 int do_crc;
18 uint32_t crc32;
19 unsigned char buffer[8192];
22 /* Checkpoint */
23 struct hashfile_checkpoint {
24 off_t offset;
25 git_hash_ctx ctx;
28 void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);
29 int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);
31 /* finalize_hashfile flags */
32 #define CSUM_CLOSE 1
33 #define CSUM_FSYNC 2
34 #define CSUM_HASH_IN_STREAM 4
36 struct hashfile *hashfd(int fd, const char *name);
37 struct hashfile *hashfd_check(const char *name);
38 struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);
39 int finalize_hashfile(struct hashfile *, unsigned char *, unsigned int);
40 void hashwrite(struct hashfile *, const void *, unsigned int);
41 void hashflush(struct hashfile *f);
42 void crc32_begin(struct hashfile *);
43 uint32_t crc32_end(struct hashfile *);
45 static inline void hashwrite_u8(struct hashfile *f, uint8_t data)
47 hashwrite(f, &data, sizeof(data));
50 static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
52 data = htonl(data);
53 hashwrite(f, &data, sizeof(data));
56 #endif