title: pclose() on file descriptor opened with popen() returns errno 10 (No child processes)
body: <p>I'm running linux and I try to do the following:</p>
  
  <ol>
  <li>Run ls on current directory (using popen)</li>
  <li>Output the result to buffer (using fread from pipe descriptor)</li>
  <li>close pipe (using pclose).</li>
  </ol>
  
  <p>Everything works fine (the buffer is filled correctly with the ls result) but when I check
  pclose() result it returns -1 and errno is set to 10 (No child processes). Have no idea why
  this is happening but I can't ignore it (unless there is a reasonable explanation to why this is happening).</p>
  
  <p>My code:</p>
  
  <pre><code>FILE * lsoutput = NULL;
  lsoutput = popen("ls -ltr", "r");
  if (readFromPipeOrFile(lsOutput, pSendBuf, pSendActualSize) == -1)
  {
          printf("readFromPipeOrFile failed.");
          pclose(lsOutput);
          safeFree(pSendBuf);
          return -1;
  }
  
  if (pclose(lsOutput) == -1) // No idea why it returns -1 but it does...
  {
          printf("pclose failed");
          printf("errno: %d\n", errno);
          printf("strerror: '%s'", strerror(errno));
          return -1;
  }
  </code></pre>
  
  <p>The code for readFromPipeOrFile (the function writing to the buffer):</p>
  
  <pre><code>int readFromPipeOrFile(FILE * pipeOrFile, char ** pSendBuf, size_t * pSendActualSize)
  {
       int multiplication = 1;
       char * pSendBufCurrentLocation = NULL;
       ERR_RETURN(pipeOrFile == NULL || pSendBuf == NULL || pSendActualSize == NULL,
                       "No values should be NULL.");
       ERR_RETURN(*pSendBuf != NULL, "*pSendBuf should be NULL");
  
       *pSendBuf = (char *) calloc (MAX_READ_FROM_STREAM * multiplication, sizeof(char));
       ERR_RETURN(*pSendBuf == NULL, "Failed allocating sendBuf");
  
       pSendBufCurrentLocation = *pSendBuf;
       while (fread(pSendBufCurrentLocation, MAX_READ_FROM_STREAM, 1, pipeOrFile) == 1)
       {
               ++multiplication;
               *pSendBuf = realloc(*pSendBuf, MAX_READ_FROM_STREAM * multiplication);
               ERR_RETURN(*pSendBuf == NULL, "Failed re-allocating sendBuf");
  
               pSendBufCurrentLocation = *pSendBuf + (MAX_READ_FROM_STREAM * (multiplication - 1));
               memset(pSendBufCurrentLocation, '\0', MAX_READ_FROM_STREAM);
       }
  
       ERR_RETURN(!feof(pipeOrFile), "Hasn't reached eof but fread stopped");
       ERR_RETURN(ferror(pipeOrFile), "Error in fread");
  
       *pSendActualSize = MAX_READ_FROM_STREAM * multiplication;
  
       return 0;
  }
  </code></pre>
  
  <p>Thanks in advance!
  EDIT: ERR_RETURN is just a macro that checks if the condition on the first paramter is true and if so, print the string in the second parameter and return -1.</p>