title: How to get octal chmod format from stat() in c
body: <p>I need to know how to get file permissions in octal format and save it to an int. I tried something like this:</p>
  
  <pre><code>struct stat buf;  
  stat(filename, &amp;buf);
  int statchmod = buf.st_mode;
  printf("chmod: %i\n", statchmod);
  </code></pre>
  
  <p>But he output was:</p>
  
  <pre><code>chmod: 33279
  </code></pre>
  
  <p>and should be 777.</p>