|
|
1.1 root 1: / Hand-coded string functions for STREAMS implementation.
2:
3: .unixorder
4:
5: .globl strlen
6:
7: string = 4
8:
9: strlen:
10: mov %edi, %edx / Preserve %edi
11: movl string(%esp), %edi / String start
12:
13: movl $-1, %ecx / Maximum string length
14: xorl %eax, %eax / Looking for 0
15: cld / Scan upwards
16: repne scasb / Find end-of-string
17:
18: movl $-2, %eax / Inital %ecx - 1
19: subl %ecx, %eax / Get iteration count - 1
20:
21: movl %edx, %edi / Restore %edi
22: ret
23:
24:
25: / String copy with length limit. An important part of the semantics of this
26: / operation is the fact that the destination is null-padded out the maximum
27: / length every time; the operating system depends on this for security at
28: / some times.
29:
30: .globl strncpy
31:
32: dest = 4
33: src = 8
34: len = 12
35:
36: strncpy:
37: movl len(%esp), %ecx / Maximum length
38: jecxz ?strncpy_done
39:
40: movl %esi, %edx / Preserve %esi
41: movl src(%esp), %esi / Get src
42:
43: pushl %edi / Preserve %edi
44: movl dest+4(%esp), %edi / Get dest, adjusting the
45: / stack offset for push
46:
47: cld / Scan upwards
48:
49: ?strncpy_loop: lodsb / %al = * %ds:%esi ++
50: stosb / * %es:%edi ++ = %al
51: orb %al, %al / %al == 0 ?
52: loopne ?strncpy_loop
53:
54: / At some point it may be profitable to look at doing the zero-fill here in
55: / 16-bit or 32-bit chunks.
56:
57: rep stosb / Pad out destination, doing
58: / nothing if %ecx == 0
59:
60: popl %edi / Restore %edi
61: movl %edx, %esi / Restore %esi
62:
63: ?strncpy_done:
64: movl dest(%esp), %eax / Return destination
65: ret
66:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.