title: Is there a C function to get permissions of a file?
body: <p>I am writing a c program to be run on UNIX, and attempting to utilize the chmod command. After consulting the man pages, i know that chmod needs two parameters. first is the permission bits, second is the file to be changed. I want to take the bitwise OR of the file's current permission bits and those entered by the user, and feed that to chmod() to change the file's permissions.</p>
  
  <p>I found the <code>access()</code> function, but am having trouble figuring out how to use it to get the permission bits of the specified file.</p>
  
  <p>What i have right now is:</p>
  
  <pre><code>octalPermissionString = strtol(argv[1], (char**)NULL, 8);
  if(chmod(argv[2], octalPermissionString | (access(argv[2], octalPermissionString)) &lt; 0) {
                      fprintf(stderr, "Permissions of file %s were not changed.\n");
                  }
  </code></pre>
  
  <p>where:</p>
  
  <p>argv[1] contains a string of a three digit decimal number entered by the user to be converted to octal and then be used as the permission bits to be bitwise OR'ed,</p>
  
  <p>argv[2] is the the file to have it's permission changed, also specified by the user.</p>
  
  <p>octalPermissionString is a long to hold the octal conversion of user input.</p>
  
  <p>Is/Are there any other functions that can return the permission bits of a given file?</p>
  
  <p>EDIT: missing close parenthesis</p>