{
unsigned int nread = 0;
unsigned int residue = addr & (sizeof(long) - 1);
+ void *const orig_addr = laddr;
while (len) {
addr &= -sizeof(long); /* aligned address */
memcpy(laddr, &u.x[residue], m);
while (residue < sizeof(long))
if (u.x[residue++] == '\0')
- return 1;
+ return (laddr - orig_addr) + residue;
residue = 0;
addr += sizeof(long);
laddr += m;
* Like `umove' but make the additional effort of looking
* for a terminating zero byte.
*
- * Returns < 0 on error, > 0 if NUL was seen,
- * (TODO if useful: return count of bytes including NUL),
+ * Returns < 0 on error, strlen + 1 if NUL was seen,
* else 0 if len bytes were read but no NUL byte seen.
*
* Note: there is no guarantee we won't overwrite some bytes
int r = vm_read_mem(pid, laddr, addr, chunk_len);
if (r > 0) {
- if (memchr(laddr, '\0', r))
- return 1;
+ char *nul_addr = memchr(laddr, '\0', r);
+
+ if (nul_addr)
+ return (nul_addr - laddr) + 1;
addr += r;
laddr += r;
nread += r;