title: How can I check if my wrapper function system call - read()  is correct?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/10260178/inline-assembler-for-wrapper-function-doesnt-work-for-some-reason">Inline Assembler for wrapper function doesn’t work for some reason</a>  </p>
  </blockquote>
  
  
  
  <p>I'm requested to write wrapper function for <code>read , write , close , open &amp; fork</code> .</p>
  
  <p>I've written 4 wrapper functions for <code>read , write , close , open</code> .</p>
  
  <p>My questions are : </p>
  
  <ol>
  <li><p>How can I write wrapper function for <code>fork</code> , using the 4 wrapper functions that I wrote for <code>read , write , close &amp; open</code> ? </p></li>
  <li><p>How can I check if the wrapper that I wrote is correct ? Here is the code for the wrapper function of <code>read</code> - called <code>my_read</code> :</p></li>
  </ol>
  
  <p></p>
  
  <pre><code>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 &lt;= res &amp;&amp; res &lt; 0)
        {
          errno = -res;
          res   = -1;
        }
  
        return res;
  }
  </code></pre>
  
  <p><strong>Remarks</strong> : I'm not allowed to use directly the <code>open ,close ,read , write &amp; fork</code> commands .</p>
  
  <p>I can attach the rest of the code of the other 3 wrappers , if it is needed . The above is the wrapper for <code>read</code>.</p>
  
  <p>Regards </p>
  
  <p>Ron</p>