Search code examples
coperating-systembsd

How to use copyout in kernel?


In the kernel space I want to copy a character from the terminal and put it in a user space.

I am trying this code, but it's not working:

char mychar;
int result;
mychar = getch();
result = copyout(&mychar, chptr, sizeof(mychr));

(chptr is a pointer to the user level space)

copyout is not returning 1. Does anyone know what the problem is?


Solution

  • Assuming a BSD-ish copyout:

    RETURN VALUES
         The copy functions return 0 on success or EFAULT if a bad address is
          encountered. ...
    

    In other words, you're just expecting something other than what it returns. :-)