-
Notifications
You must be signed in to change notification settings - Fork 0
/
td_yield_set_zero.c
46 lines (42 loc) · 1007 Bytes
/
td_yield_set_zero.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
** Copyright 2015 K.J. Hermans (kees.jan.hermans@gmail.com)
** This code is part of simpledbm, an API to a dbm on a finite resource.
** License: BSD
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "td_private.h"
/**
* \ingroup btree_private
*
* Set administrated empty space to zero.
*
* \param td Non-NULL pointer to initialized td_t structure.
* \param off Offset to the chunk to be zeroised.
*
* \returns Zero on success, or non-zero on failure.
*/
int td_yield_set_zero
(td_t* td, unsigned off)
{
unsigned char zerobuf[ 256 ];
unsigned size;
memset(zerobuf, 0, sizeof(zerobuf));
CHECK(td_read_uint(td, off + sizeof(unsigned), &size));
if (size < (2 * sizeof(unsigned))) {
return TDERR_BOUNDS;
}
off += (2 * sizeof(unsigned));
size -= (2 * sizeof(unsigned));
while (size) {
unsigned l = ((size > sizeof(zerobuf)) ? sizeof(zerobuf) : size);
CHECK(td_write(td, off, zerobuf, l));
off += l;
size -= l;
}
return 0;
}
#ifdef __cplusplus
}
#endif