LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Calling system calls in C runtime (in the run-time) (https://www.linuxquestions.org/questions/programming-9/calling-system-calls-in-c-runtime-in-the-run-time-834046/)

msaslin 09-23-2010 12:12 PM

Calling system calls in C runtime (in the run-time)
 
I know there is a way to call winapi in runtime in windows. I want to ask how can I call a system call in gcc in runtime (when I don't know what it can be)?
I don't mean syscall that I think is for calling only system calls and not library functions.

Thanks!

msaslin 09-23-2010 03:27 PM

what's syscall of linux's equivalence in freebsd? Though it is only for kernel system calls. Calling system calls is with int 80 in asm, how is it for the (static and shared) library functions? How do they work?

paulsm4 09-23-2010 06:48 PM

Hi -

The "moral equivalent" to the Win32 API for Linux is "glibc", the Gnu C runtime library.

Standard library calls like "open()" and "fork()" are thin wrappers around the actual system calls (for example, "asm int 80" for some kernels).

You can learn more about "how it works" here:

http://www.gnu.org/software/libc/man...l#System-Calls

You can get complete source and study it yourself here:

http://www.gnu.org/software/libc/

'Hope that helps

gothrog 09-23-2010 10:38 PM

This is the way it was on a linux box about 5 years ago. I don't think it changed much. I would think it should work the same assuming you are using cygwin.

std::string moveAFile = "mv test1 test2";
int check = system(moveAFile.c_str());

Best of luck,

Mike

JohnGraham 09-24-2010 03:28 AM

Quote:

Originally Posted by msaslin (Post 4106885)
I know there is a way to call winapi in runtime in windows. I want to ask how can I call a system call in gcc in runtime (when I don't know what it can be)?
I don't mean syscall that I think is for calling only system calls and not library functions.

Thanks!

If you're asking about opening shared libraries dynamically at run-time, then dlopen(), dlsym() and dlclose() might be what you're looking for - they all share the same manpage.


All times are GMT -5. The time now is 12:18 PM.