title: Linux: Attempting to get joystick vendor and product IDs via ioctl, get EINVAL instead
body: <p>I'm attempting to read the name, vendor ID and product ID for a USB joystick on Ubuntu (specifically I'm working with a wired Xbox 360 pad on Ubuntu 13.10 x64). I can read the name but when attempting to read the vendor and product IDs I get an <code>EINVAL</code> error. The code is as follows:</p>
  
  <pre><code>if (plugged[index])
  {
      char name[32];
      std::snprintf(name, sizeof(name), "/dev/input/js%u", index);
  
      // Open the joystick's file descriptor (read-only and non-blocking)
      m_file = ::open(name, O_RDONLY | O_NONBLOCK);
      if (m_file &gt;= 0)
      {
          // Retrieve the axes mapping
          ioctl(m_file, JSIOCGAXMAP, m_mapping);
  
          // Get the name
          char joyname[128];
          if (ioctl(m_file, JSIOCGNAME(128), joyname) &lt; 0) {
              m_name = "Unknown Joystick";
          } else {
              m_name = joyname;
          }
  
          // Get vendor and product IDs
          input_id inpid;
          if (ioctl(m_file, EVIOCGID, &amp;inpid) &lt; 0) {
              if (errno == EBADF) printf("EBADF\n");
              if (errno == EFAULT) printf("EFAULT\n");
              if (errno == ENOTTY) printf("ENOTTY\n");
              if (errno == EINVAL) printf("EINVAL\n");
              m_manufacturerID = 0;
              m_productID = 0;
          } else {
              m_manufacturerID = inpid.vendor;
              m_productID = inpid.product;
          }
  
          // Reset the joystick state
          m_state = JoystickState();
  
          return true;
      }
      else
      {
          return false;
      }
  }
  else
  {
      return false;
  }
  </code></pre>
  
  <p>The snippet that reads vendor and product IDs is:</p>
  
  <pre><code>ioctl(m_file, EVIOCGID, &amp;inpid)
  </code></pre>
  
  <p>According the <a href="http://man7.org/linux/man-pages/man2/ioctl.2.html" rel="nofollow">man page for ioctl</a>, <code>EINVAL</code> the <em>request</em> (<code>EVIOCGID</code>) or <em>argp</em> (<code>inpid</code>) is invalid.</p>
  
  <p>How can I determine which is invalid?</p>