FOSSology  4.4.0
Open Source License Compliance by Open Source Software
checksum.h
1 /*
2  checksum.h - Checksum computation header file
3 
4  SPDX-FileCopyrightText: © 2007-2011 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
8 #ifndef CHECKSUM_H
9 #define CHECKSUM_H
10 
11 #include <stdint.h> /* for uint8_t */
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include <errno.h>
17 #include <sys/mman.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <fcntl.h>
21 #include <dirent.h>
22 
23 #ifdef STANDALONE
24 #include "standalone.h"
25 #else
26 #include "libfossology.h"
27 #endif
28 
32 struct Cksum
33 {
34  uint8_t MD5digest[16];
35  uint8_t SHA1digest[20];
36  uint64_t DataLen;
37 };
38 typedef struct Cksum Cksum;
39 
43 struct CksumFile
44 {
45  int FileHandle;
46  unsigned char *Mmap;
47  uint64_t MmapSize;
48  uint64_t MmapOffset;
49 };
50 typedef struct CksumFile CksumFile;
51 
52 CksumFile * SumOpenFile (char *Fname);
53 void SumCloseFile (CksumFile *CF);
54 int CountDigits (uint64_t Num);
55 Cksum * SumComputeFile (FILE *Fin);
57 char * SumToString (Cksum *Sum);
58 int calc_sha256sum(char* filename, char* dst);
59 #endif
char * SumToString(Cksum *Sum)
Return string representing a Cksum. NOTE: The calling function must free() the string!
Definition: checksum.c:237
Cksum * SumComputeBuff(CksumFile *CF)
Compute the checksum, allocate and return a Cksum containing the sum value.
Definition: checksum.c:182
int CountDigits(uint64_t Num)
Count how many digits are in a number.
Definition: checksum.c:97
Cksum * SumComputeFile(FILE *Fin)
Compute the checksum, allocate and return a string containing the sum value.
Definition: checksum.c:115
CksumFile * SumOpenFile(char *Fname)
Open and mmap a file.
Definition: checksum.c:26
void SumCloseFile(CksumFile *CF)
Close a file that was opened with SumOpenFile()
Definition: checksum.c:83
The main FOSSology C library.
Store file handler and mmap of a file.
Definition: checksum.h:44
int FileHandle
File handler for the file.
Definition: checksum.h:45
unsigned char * Mmap
Mmap of the file.
Definition: checksum.h:46
uint64_t MmapSize
Size of mmap.
Definition: checksum.h:47
uint64_t MmapOffset
Index into mmap.
Definition: checksum.h:48
Store check sum of a file.
Definition: checksum.h:33
uint8_t SHA1digest[20]
SHA1 digest of the file.
Definition: checksum.h:35
uint64_t DataLen
Size of the file.
Definition: checksum.h:36
uint8_t MD5digest[16]
MD5 digest of the file.
Definition: checksum.h:34