title: How to use "sudo" from a C program without using system()?
body: <p>I have the following code:</p>
  
  <pre><code>std::string cmd = "sudo chmod a+x file";
  int r = system(cmd.c_str());
  </code></pre>
  
  <p>which works correctly.</p>
  
  <p>How can I do the same thing without calling the system() function?</p>
  
  <p>What I can get to is:</p>
  
  <pre><code>#include &lt;sys/stat.h&gt;
  int r = chmod("file", S_IXUSR | S_IXGRP | S_IXOTH);
  </code></pre>
  
  <p>How can I use "sudo" in this case?</p>
  
  <p>Thank you.</p>