1
/* mem.c - array-of-byte functions
3
****************************************************************
4
* Copyright (C) 1998, 2000 Thomas Lord
6
* See the file "COPYING" for further information about
7
* the copyright and warranty status of this work.
12
#include "hackerlab/mem/mem.h"
15
/************************************************************************
16
*(h1 "Array-of-Byte Functions"
17
* :includes ("hackerlab/mem/mem.h"))
19
* These functions operate on regions of memory as arrays of unsigned
20
* bytes with no further interpretation.
25
* void mem_set (t_uchar * mem, unsigned int c, size_t size);
27
* Store `size' bytes of value `c' beginning at `mem'.
30
mem_set (t_uchar * mem, unsigned int c, size_t size)
38
* void mem_set0 (t_uchar * mem, size_t n);
40
* Store `n' 0 bytes beginning at `mem'.
43
mem_set0 (t_uchar * mem, size_t n)
51
* void mem_move (t_uchar * to, const t_uchar * from, size_t amt);
53
* Copy `amt' bytes from `from' to `to'. The source and destination
54
* regions may overlap.
57
mem_move (t_uchar * to, const t_uchar * from, size_t amt)
77
* int mem_cmp (const t_uchar * m1, const t_uchar * m2, size_t amt);
79
* Compare `amt' bytes starting at `m1' and `m2'. If a difference is
80
* found, immediately return -1 if the differing byte in `m1' is less
81
* than the byte in `m2', 1 otherwise. If no difference is found,
85
mem_cmp (const t_uchar * m1, const t_uchar * m2, size_t amt)
92
return (*m1 < *m2) ? -1 : 1;
99
* size_t mem_occurrences (const t_uchar * mem,
103
* Search `size' bytes of data for occurences of byte `c' beginning at
104
* `mem'. Return the number of occurences found.
107
mem_occurrences (const t_uchar * mem,