user2213232
user2213232

Reputation: 13

Different ways to call system calls

I observed that system call "stat" is behaving differently with calls

stat()

syscall(__NR_stat) 

I do not understand why same system call is behaving differently just because way to call it is changed?

Upvotes: 0

Views: 246

Answers (2)

Chris Stratton
Chris Stratton

Reputation: 40407

The stat() provided by a C library on Linux today is usually implemented on top of the kernel 's sys_stat64().

This is one of the many cases where the man page should be your first reference:

  Underlying kernel interface

   Over time, increases in the size of the stat structure have led to
   three successive versions of stat(): sys_stat() (slot __NR_oldstat),
   sys_newstat() (slot __NR_stat), and sys_stat64() (new in kernel 2.4;
   slot __NR_stat64).  The glibc stat() wrapper function hides these
   details from applications, invoking the most recent version of the
   system call provided by the kernel, and repacking the returned
   information if required for old binaries.  Similar remarks apply for
   fstat() and lstat().

You may also want to obtain the source package for your installed C library and look through it for the actual implementation of the wrapper.

Upvotes: 1

0xDen
0xDen

Reputation: 92

If it is C code, then you should realize, that you have some syntax errors. But anyway, on platforms there may be different values of __NR_stat marcro. To find out this, you have to see /usr/include/unistd.h file. And who knows what's the sequencies of calling these functions? Please, give us more information.

Upvotes: 0

Related Questions