A.5 C memory operation functions
The following 10 functions are available as replacements for existing C library
memory operation functions. To use these you must include mpatrol.h
before all other header files, although on UNIX and Windows platforms (and
AmigaOS when using gcc) they will be used anyway, albeit with slightly
less tracing information.
void *memset(void *ptr, int byte, size_t size)
- Writes size bytes of value byte to the memory location beginning at
ptr and returns ptr. If size is `0' then no bytes will
be written. If the operation would affect an existing memory allocation in the
heap but would straddle that allocation's boundaries then an error message will
be generated in the log file and no bytes will be written.
void bzero(void *ptr, size_t size)
- Writes size zero bytes to the memory location beginning at ptr. If
size is `0' then no bytes will be written. If the operation would
affect an existing memory allocation in the heap but would straddle that
allocation's boundaries then an error message will be generated in the log file
and no bytes will be written. This function is available for backwards
compatibility with older C libraries and should not be used in new code.
void *memccpy(void *dest, const void *src, int byte, size_t size)
- Copies size bytes from src to dest and returns `NULL', or
copies the number of bytes up to and including the first occurrence of
byte if byte exists within the specified range and returns a pointer
to the first byte after byte. If size is `0' or src is
the same as dest then no bytes will be copied. The source and destination
ranges should not overlap, otherwise a warning will be written to the log file.
If the operation would affect an existing memory allocation in the heap but
would straddle that allocation's boundaries then an error message will be
generated in the log file and no bytes will be copied.
void *memcpy(void *dest, const void *src, size_t size)
- Copies size bytes from src to dest and returns dest. If
size is `0' or src is the same as dest then no bytes will
be copied. The source and destination ranges should not overlap, otherwise a
warning will be written to the log file. If the operation would affect an
existing memory allocation in the heap but would straddle that allocation's
boundaries then an error message will be generated in the log file and no bytes
will be copied.
void *memmove(void *dest, const void *src, size_t size)
- Copies size bytes from src to dest and returns dest. If
size is `0' or src is the same as dest then no bytes will
be copied. If the operation would affect an existing memory allocation in the
heap but would straddle that allocation's boundaries then an error message will
be generated in the log file and no bytes will be copied.
void bcopy(const void *src, void *dest, size_t size)
- Copies size bytes from src to dest. If size is `0'
or src is the same as dest then no bytes will be copied. If the
operation would affect an existing memory allocation in the heap but would
straddle that allocation's boundaries then an error message will be generated in
the log file and no bytes will be copied. This function is available for
backwards compatibility with older C libraries and should not be used in new
code.
int memcmp(const void *ptr1, const void *ptr2, size_t size)
- Compares size bytes from ptr1 and ptr2 and returns `0' if
all of the bytes are identical, or returns the byte difference of the first
differing bytes. If size is `0' or ptr1 is the same as
ptr2 then no bytes will be compared. If the operation would read from an
existing memory allocation in the heap but would straddle that allocation's
boundaries then an error message will be generated in the log file and no bytes
will be compared.
int bcmp(const void *ptr1, const void *ptr2, size_t size)
- Compares size bytes from ptr1 and ptr2 and returns `0' if
all of the bytes are identical, or returns the byte difference of the first
differing bytes. If size is `0' or ptr1 is the same as
ptr2 then no bytes will be compared. If the operation would read from an
existing memory allocation in the heap but would straddle that allocation's
boundaries then an error message will be generated in the log file and no bytes
will be compared. This function is available for backwards compatibility with
older C libraries and should not be used in new code.
void *memchr(const void *ptr, int byte, size_t size)
- Searches up to size bytes in ptr for the first occurrence of
byte and returns a pointer to it or `NULL' if no such byte occurs.
If size is `0' then no bytes will be searched. If the operation
would affect an existing memory allocation in the heap but would straddle that
allocation's boundaries then an error message will be generated in the log file
and no bytes will be searched.
void *memmem(const void *ptr1, size_t size1, const void *ptr2, size_t size2)
- Searches up to size1 bytes in ptr1 for the first occurrence of
ptr2 (which is exactly size2 bytes in length) and returns a pointer
to it or `NULL' if no such sequence of bytes occur. If size1 or
size2 is `0' then no bytes will be searched. If the operation would
affect an existing memory allocation in the heap but would straddle that
allocation's boundaries then an error message will be generated in the log file
and no bytes will be searched.