1memory(3C) Standard C Library Functions memory(3C)
2
3
4
6 memory, memccpy, memchr, memcmp, memcpy, memmove, memset - memory oper‐
7 ations
8
10 #include <string.h>
11
12 void *memccpy(void *restrict s1, const void *restrict s2,
13 int c, size_t n);
14
15
16 void *memchr(const void *s, int c, size_t n);
17
18
19 int memcmp(const void *s1, const void *s2, size_t n);
20
21
22 void *memcpy(void *restrict s1, const void *restrict s2, size_t n);
23
24
25 void *memmove(void *s1, const void *s2, size_t n);
26
27
28 void *memset(void *s, int c, size_t n);
29
30
31 ISO C++
32 #include <string.h>
33
34 const void *memchr(const void *s, int c, size_t n);
35
36
37 #include <cstring>
38
39 void *std::memchr(void *s, int c, size_t n);
40
41
43 These functions operate as efficiently as possible on memory areas
44 (arrays of bytes bounded by a count, not terminated by a null charac‐
45 ter). They do not check for the overflow of any receiving memory area.
46
47
48 The memccpy() function copies bytes from memory area s2 into s1, stop‐
49 ping after the first occurrence of c (converted to an unsigned char)
50 has been copied, or after n bytes have been copied, whichever comes
51 first. It returns a pointer to the byte after the copy of c in s1, or a
52 null pointer if c was not found in the first n bytes of s2.
53
54
55 The memchr() function returns a pointer to the first occurrence of c
56 (converted to an unsigned char) in the first n bytes (each interpreted
57 as an unsigned char) of memory area s, or a null pointer if c does not
58 occur.
59
60
61 The memcmp() function compares its arguments, looking at the first n
62 bytes (each interpreted as an unsigned char), and returns an integer
63 less than, equal to, or greater than 0, according as s1 is lexicograph‐
64 ically less than, equal to, or greater than s2 when taken to be
65 unsigned characters.
66
67
68 The memcpy() function copies n bytes from memory area s2 to s1. It
69 returns s1. If copying takes place between objects that overlap, the
70 behavior is undefined.
71
72
73 The memmove() function copies n bytes from memory area s2 to memory
74 area s1. Copying between objects that overlap will take place cor‐
75 rectly. It returns s1.
76
77
78 The memset() function sets the first n bytes in memory area s to the
79 value of c (converted to an unsigned char). It returns s.
80
82 Using memcpy() might be faster than using memmove() if the application
83 knows that the objects being copied do not overlap.
84
86 See attributes(5) for descriptions of the following attributes:
87
88
89
90
91 ┌─────────────────────────────┬─────────────────────────────┐
92 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
93 ├─────────────────────────────┼─────────────────────────────┤
94 │Interface Stability │Stable │
95 ├─────────────────────────────┼─────────────────────────────┤
96 │MT-Level │MT-Safe │
97 ├─────────────────────────────┼─────────────────────────────┤
98 │Standard │See standards(5). │
99 └─────────────────────────────┴─────────────────────────────┘
100
102 string(3C), attributes(5), standards(5)
103
105 Overlap between objects being copied can arise even when their (vir‐
106 tual) address ranges appear to be disjoint; for example, as a result of
107 memory-mapping overlapping portions of the same underlying file, or of
108 attaching the same shared memory segment more than once.
109
110
111
112SunOS 5.11 4 Feb 2009 memory(3C)