Including <sys/syscall.h> works but must also include <errno.h>
Also, including <linux/unistd.h> works but must also include <errno.h>
Thanks for your help.
-Aman
On 6/24/05, Bob Bennett <Robert.Bennett@xxxxxx> wrote:
On Fri, 2005-06-24 at 15:21, Aman Wardak wrote:
> On page 73, he has put down 2 lines of code that we can use to use
> the open system call without explicit library support. The book reads
> "Placing this macro in an application is all that is required to use
> the open() system call". I have used these 2 lines in my code as
> follows:
>
> #define __NR_open 5
> _syscall3(long, open, const char *, filename, int, flags, int, mode)
>
_syscall3 is a macro defined in asm/unistd.h, included from
sys/syscall.h. Add a '#include <sys/syscall.h>' at the top, and delete
the line that defines __NR_open (it is also defined when you include
sys/syscall.h).
> int main()
> {
> long ret;
>
> ret = open("/root/tmp", 02, 00700);
>
> return ret;
> }
>
>
> However i get this when compiling:
>
> # gcc syscall_open.c
> syscall_open.c:3: parse error before "open"
> syscall_open.c: In function `_syscall3':
> syscall_open.c:6: parse error before '{' token
> syscall_open.c:6: declaration for parameter `main' but no such parameter
>
>
> What am I doing wrong?
>
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive: http://mail.nl.linux.org/kernelnewbies/
> FAQ: http://kernelnewbies.org/faq/
>
>