How to check if my system-function read () is correct?

Possible duplicate:
Inline Assembler for shell function does not work for some reason

I need to write a wrapper function for read , write , close , open & fork.

I wrote 4 wrapper functions for read , write , close , open.

My questions:

  • How to write a wrapper function for forkusing the 4 wrapper functions that I wrote for read , write , close & open?

  • How to check if the wrapper is spelled correctly? Here is the code for the wrapping function read- called my_read:

ssize_t my_read(int fd, void *buf, size_t count)   
{    
      ssize_t res;

      __asm__ volatile(
        "int $0x80"        /* make the request to the OS */
        : "=a" (res),       /* return result in eax ("a") */
          "+b" (fd),     /* pass arg1 in ebx ("b") */
          "+c" (buf),     /* pass arg2 in ecx ("c") */
          "+d" (count)      /* pass arg3 in edx ("d") */
        : "a"  (5)          /* passing the system call for read to %eax , with call number 5  */
        : "memory", "cc"); 

      /* The operating system will return a negative value on error;
       * wrappers return -1 on error and set the errno global variable */

      if (-125 <= res && res < 0)
      {
        errno = -res;
        res   = -1;
      }

      return res;
}

Notes : I am not allowed to use commands directly open ,close ,read , write & fork.

I can attach the rest of the code of the other 3 wrappers if necessary. The above shell for read.

Yours faithfully

Ron

+3
1

2,

    __asm__ volatile ("int $0x80" : "=a" (res) : "0" (2)); 

. , fork , res pid ( ) 0 ( ).

0

All Articles