memory 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. .TH MEMORY 2
  2. .SH NAME
  3. memccpy, memchr, memcmp, memcpy, memmove, memset \- memory operations
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .ta \w'\fLvoid* 'u
  10. .B
  11. void* memccpy(void *s1, void *s2, int c, ulong n)
  12. .PP
  13. .B
  14. void* memchr(void *s, int c, ulong n)
  15. .PP
  16. .B
  17. int memcmp(void *s1, void *s2, ulong n)
  18. .PP
  19. .B
  20. void* memcpy(void *s1, void *s2, ulong n)
  21. .PP
  22. .B
  23. void* memmove(void *s1, void *s2, ulong n)
  24. .PP
  25. .B
  26. void* memset(void *s, int c, ulong n)
  27. .SH DESCRIPTION
  28. These functions operate efficiently on memory areas
  29. (arrays of bytes bounded by a count, not terminated by a zero byte).
  30. They do not check for the overflow of any receiving memory area.
  31. .PP
  32. .I Memccpy
  33. copies bytes from memory area
  34. .I s2
  35. into
  36. .IR s1 ,
  37. stopping after the first occurrence of byte
  38. .I c
  39. has been copied, or after
  40. .I n
  41. bytes have been copied, whichever comes first.
  42. It returns a pointer to the byte after
  43. the copy of
  44. .I c
  45. in
  46. .IR s1 ,
  47. or zero if
  48. .I c
  49. was not found in the first
  50. .I n
  51. bytes of
  52. .IR s2 .
  53. .PP
  54. .I Memchr
  55. returns a pointer to the first
  56. occurrence of byte
  57. .I c
  58. in the first
  59. .I n
  60. bytes of memory area
  61. .IR s,
  62. or zero if
  63. .I c
  64. does not occur.
  65. .PP
  66. .I Memcmp
  67. compares its arguments, looking at the first
  68. .I n
  69. bytes only, and returns an integer
  70. less than, equal to, or greater than 0,
  71. according as
  72. .I s1
  73. is lexicographically less than, equal to, or
  74. greater than
  75. .IR s2 .
  76. The comparison is bytewise unsigned.
  77. .PP
  78. .I Memcpy
  79. copies
  80. .I n
  81. bytes from memory area
  82. .I s2
  83. to
  84. .IR s1 .
  85. It returns
  86. .IR s1 .
  87. .PP
  88. .I Memmove
  89. works like
  90. .IR memcpy ,
  91. except that it is guaranteed to work if
  92. .I s1
  93. and
  94. .IR s2
  95. overlap.
  96. .PP
  97. .I Memset
  98. sets the first
  99. .I n
  100. bytes in memory area
  101. .I s
  102. to the value of byte
  103. .IR c .
  104. It returns
  105. .IR s .
  106. .SH SOURCE
  107. All these routines have portable C implementations in
  108. .BR /sys/src/libc/port .
  109. Most also have machine-dependent assembly language implementations in
  110. .BR /sys/src/libc/$objtype .
  111. .SH SEE ALSO
  112. .IR strcat (2)
  113. .SH BUGS
  114. ANSI C does not require
  115. .I memcpy
  116. to handle overlapping source and destination; on Plan 9, it does, so
  117. .I memmove
  118. and
  119. .I memcpy
  120. behave identically.
  121. .PP
  122. If
  123. .I memcpy
  124. and
  125. .I memmove
  126. are handed a negative count, they abort.