-1

hey I would like to open and read a file using system calls and print the data in it letter by letter I have the function system_call in an assembly file and I want to "save" to pointer to the file descriptor from the system_call(SYS_OPEN to use it. the purpose is not using #include directory

my code is

system_call(SYS_OPEN,argv[2],0,)

where argv[2] = "a.txt" SYS_OPEN = 5 and the 4th param should be permission, and i dont know what to write there

after "saving" it to pointer I would like to read and print like this

while(system_call(SYS_READ,STDIN, input_char , 1)>0)
  {
  system_call(SYS_WRITE,STDOUT,input_char, 1);
  }

thank you.

Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69

3 Answers3

2

That's a list of system calls (may be a but outdated, but will work for you) http://asm.sourceforge.net/syscall.html .You can check an implementation details and usage of system_call in appropriate linux kernel sources for sys_open, sys_read, sys_write etc..

evilruff
  • 3,947
  • 1
  • 15
  • 27
1

You could write code to do this using library functions (i.e. open(2), read(2)), then run the program under strace to see the function calls it makes and parameters it uses, then replicate that in your own code....

Tony Delroy
  • 102,968
  • 15
  • 177
  • 252
0

Got it by using int as pointer to file:

char input_char[1];
int file = system_call(SYS_OPEN,argv[j],0,0777);

while(system_call(SYS_READ,file, input_char , 1) >0 )
  {
  system_call(SYS_WRITE,STDOUT,input_char, 1);
  }

Thanks you for your comments and help

Aviram Fireberger
  • 3,910
  • 5
  • 50
  • 69