title: error in mq_open: invalid argument
body: <p>Can anyone help me point out where is the errors in my code?<br>
  Thank you in advance.</p>
  
  <p>Here is my code.I delete header files in code below.When I ran these code ,I always receive </p>
  
  <blockquote>
    <p>:mq_open:invalid argument</p>
  </blockquote>
  
  <pre><code>#define FILE_MODE S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH
  struct mq_attr attr;
  int main (int argc,char **argv)
  {
      int c;
      int flags;
      mqd_t mqd;
  
      flags = O_RDWR|O_CREAT;
  
      while ( (c = getopt (argc,argv,"em:z:")) != -1) {
          switch (c) {
              case 'e':
                  flags |= O_EXCL;
                  continue;
  
              case 'm':
                  attr.mq_maxmsg = atol (optarg);
                  break;
  
              case 'z':
                  attr.mq_msgsize = atol (optarg);
                  break;
          }
      }
  
      if (optind != argc - 1) {
          printf ("usage:mqcreate [-e] [-m maxseg -z msgsize] &lt;name&gt;\n");
          exit (1);
      }
  
      if ((attr.mq_maxmsg != 0 &amp;&amp; attr.mq_msgsize == 0) ||
              (attr.mq_maxmsg == 0 &amp;&amp; attr.mq_msgsize != 0))
      {
          printf ("must specify both -m maxmsg and -z msgsize\n");
          exit (1);
      }
  
      if (attr.mq_msgsize == 0 &amp;&amp; attr.mq_maxmsg == 0)
      {
          attr.mq_msgsize = 10;
          attr.mq_maxmsg = 10;
      }
  
  
      mqd = mq_open (argv[optind],flags,FILE_MODE,&amp;attr);
      if (mqd == -1) {
         perror ("mq_open");
         exit (1);
     }
  
     mq_close (mqd);
  
     return 0;
  }
  </code></pre>
  
  <p>I search stackoverflow for this question,but none helps me.<br>
  Thank you.</p>