00001 /** @file include/dmlite/c/utils.h 00002 * @brief C wrapper for DMLite utils. 00003 * @author Alejandro Álvarez Ayllon <aalvarez@cern.ch> 00004 */ 00005 #ifndef DMLITE_CHECKSUMS_H 00006 #define DMLITE_CHECKSUMS_H 00007 00008 #include <stddef.h> 00009 #include "io.h" 00010 00011 #ifdef __cplusplus 00012 extern "C" { 00013 #endif 00014 00015 /** 00016 * @brief Puts into output the full name of the checksum algorithm 00017 * specified with shortName. 00018 * @param shortName The checksum short name (CS, AD, MD) 00019 * @param output The full name will be put here. 00020 * @param osize The size of the buffer pointed by output. 00021 * @return The same value as the pointer output 00022 */ 00023 char* dmlite_checksum_full_name(const char* shortName, char* output, 00024 size_t osize); 00025 /** 00026 * @brief Puts into output the short name of the checksum algorithm 00027 * specified with longName. 00028 * @param shortName The checksum long name (MD5, ADLER32, ...) 00029 * @param output The short name will be put here. 00030 * @param osize The size of the buffer pointed by output. 00031 * @return The same value as the pointer output 00032 */ 00033 char* dmlite_checksum_short_name(const char* longName, char* output, 00034 size_t osize); 00035 00036 /** 00037 * @brief Generated the MD5 checksum of the given file. 00038 * @param fd The file descriptor where to read the data to digest. 00039 * @param offset Where to start to digest. 00040 * @param size The number of bytes to digest. 0 means the whole file. 00041 * @param output Where to put the resulting checksum (in hexadecimal) 00042 * @param outsize The size of the memory area pointed by output. 00043 * @return 0 on success, error code otherwise. 00044 */ 00045 int dmlite_checksum_md5(dmlite_fd* fd, off_t offset, off_t size, 00046 char* output, size_t outsize); 00047 00048 /** 00049 * @brief Generated the CRC32 checksum of the given file. 00050 * @param fd The file descriptor where to read the data to digest. 00051 * @param offset Where to start to digest. 00052 * @param size The number of bytes to digest. 0 means the whole file. 00053 * @param output Where to put the resulting checksum (in decimal) 00054 * @param outsize The size of the memory area pointed by output. 00055 * @return 0 on success, error code otherwise. 00056 */ 00057 int dmlite_checksum_crc32(dmlite_fd* fd, off_t offset, off_t size, 00058 char* output, size_t outsize); 00059 00060 /** 00061 * @brief Generated the Adler32 checksum of the given file. 00062 * @param fd The file descriptor where to read the data to digest. 00063 * @param offset Where to start to digest. 00064 * @param size The number of bytes to digest. 0 means the whole file. 00065 * @param output Where to put the resulting checksum (in hexadecimal) 00066 * @param outsize The size of the memory area pointed by output. 00067 * @return 0 on success, error code otherwise. 00068 */ 00069 int dmlite_checksum_adler32(dmlite_fd* fd, off_t offset, off_t size, 00070 char* output, size_t outsize); 00071 00072 #ifdef __cplusplus 00073 } 00074 #endif 00075 00076 #endif /* DMLITE_CHECKSUMS_H */