mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-05 16:00:05 +01:00
Add uint64_to_str helper.
This commit is contained in:
@@ -149,6 +149,8 @@ unsigned crypt_cpusonline(void);
|
||||
|
||||
int init_crypto(struct crypt_device *ctx);
|
||||
|
||||
const char *uint64_to_str(char *buffer, size_t size, const uint64_t *val);
|
||||
|
||||
void logger(struct crypt_device *cd, int class, const char *file, int line, const char *format, ...) __attribute__ ((format (printf, 5, 6)));
|
||||
#define log_dbg(x...) logger(NULL, CRYPT_LOG_DEBUG, __FILE__, __LINE__, x)
|
||||
#define log_std(c, x...) logger(c, CRYPT_LOG_NORMAL, __FILE__, __LINE__, x)
|
||||
|
||||
14
lib/utils.c
14
lib/utils.c
@@ -45,6 +45,20 @@ unsigned crypt_cpusonline(void)
|
||||
return r < 0 ? 1 : r;
|
||||
}
|
||||
|
||||
const char *uint64_to_str(char *buffer, size_t size, const uint64_t *val)
|
||||
{
|
||||
int r = snprintf(buffer, size, "%" PRIu64, *val);
|
||||
if (r < 0) {
|
||||
log_dbg("Failed to convert integer to string.");
|
||||
*buffer = '\0';
|
||||
} else if ((size_t)r >= size) {
|
||||
log_dbg("Not enough space to store '%" PRIu64 "' to a string buffer.", *val);
|
||||
*buffer = '\0';
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
ssize_t read_buffer(int fd, void *buf, size_t count)
|
||||
{
|
||||
size_t read_size = 0;
|
||||
|
||||
Reference in New Issue
Block a user