I was wondering if strcpy or strcat like functions causes any system call or they are handled internally by the OS?
Asked
Active
Viewed 1,990 times
1
-
1When in doubt, you can run your binary through `strace` which will show you system calls that the binary performs. – smani Feb 07 '14 at 14:27
-
1yes. i did that. and strace doesn't show any system call for those functions. that made me ask you guys... how this kind of operation is handled? is there any way to catch those events? – Asish Biswas Feb 07 '14 at 14:31
-
4You can try the [ltrace](http://ltrace.alioth.debian.org/) for library traces. The str functions don't make system calls. – Keith Feb 07 '14 at 14:33
3 Answers
6
No system call is involved. In fact, the source code of most if not all implementations would look like this:
char *
strcpy(char *s1, const char *s2) {
char *s = s1;
while ((*s++ = *s2++) != 0) ;
return (s1);
}
strcat
is similar:
char *
strcat(char *s1, const char *s2)
{
strcpy(&s1[strlen(s1)], s2);
return s1;
}

Stefano Sanfilippo
- 32,265
- 7
- 79
- 80
4
On Linux, those calls are implemented by the standard library (and those are part of the standard C library). See also glibc. System calls are invocations from user code to kernel code for hardware access (e.g. memory allocation); they are accomplished with an interrupt 0x80.

Community
- 1
- 1

Elliott Frisch
- 198,278
- 20
- 158
- 249
-
Yes, but this fact gives no information pertaining systems calls. – Stefano Sanfilippo Feb 07 '14 at 14:27
-
@StefanoSanfilippo Added some general information pertaining to system calls. – Elliott Frisch Feb 07 '14 at 14:30
-
1Yes it does: these functions are implemented in the C runtime library which is regular unprivileged code, NOT a system call which is a call to privileged OS functions in the kernel. – Colin D Bennett Feb 07 '14 at 14:31
4
No OS calls are REQUIRED for such simple operations - they can be performed easily in the libraries.
Note that the OS may be entered during such calls, eg. because they generate a page-fault or some other hardware interrupt occurs.

Martin James
- 24,453
- 3
- 36
- 60