title: Capturing stdout/stderr with NDK
body: <p>I am porting some existing C code to run on Android. This C code writes lots of output to stdout/stderr. I need to capture this output, either in a memory buffer or a file, so I can then send it by email or otherwise share it.</p>
  
  <p>How can I achieve this, ideally without modifying the existing C code?</p>
  
  <p>Note: this question is <strong>NOT</strong> about redirecting the output to adb or logcat; I need to buffer the output locally on the device. I am aware of the following questions, which do not appear to address my query:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5499202/why-is-redirecting-stdout-stderr-on-android-not-working">Why is redirecting stdout/stderr on android not working?</a></li>
  <li><a href="https://stackoverflow.com/questions/7719827/android-ndk-native-lib-what-to-do-about-existing-stdio">Android NDK Native LIB, What to do about existing stdio?</a></li>
  </ul>