title: Unable to read file contents into buffer using read()
body: <p>Following is a sample code compiled using GNU compiler (g++ command) on an Ubuntu OS 16.04:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;unistd.h&gt;
  #include&lt;fcntl.h&gt;
  #include &lt;errno.h&gt;
  int main()
  {           char* pBuffer;          
  
              char* storedfilepath = "/home/rtpl/Desktop/ts.mp4";
  
              std::cout&lt;&lt;"\n Opening file at "&lt;&lt;storedfilepath&lt;&lt;"\n";
  
              int NumBytesToRead = 1000 ;
              int filedes = open(storedfilepath,O_RDONLY);
  
              std::cout&lt;&lt;"\n value of error is "&lt;&lt;errno&lt;&lt;"\n";
  
              std::cout&lt;&lt;"\n value of filedes is "&lt;&lt;filedes;
  
              if (filedes==0)
              std::cout&lt;&lt;"\n File cannot be opened";
              else
              {
              std::cout&lt;&lt;"\n File opened successfully";
              std::cout&lt;&lt;"\n Now reading file\n"; 
  
              }
  
              //if(
              int ret = read(filedes,pBuffer,NumBytesToRead);
  
              std::cout&lt;&lt;"\n value of error is "&lt;&lt;errno&lt;&lt;"\n";
  
              if(ret!= -1)
              std::cout&lt;&lt;"\n File read successfully";
              else
              std::cout&lt;&lt;"\n File contents cannot be read";   
  
              std::cout&lt;&lt;"\nEnd.\n";  
  
              close(filedes);
              return 0;
  
  } 
  </code></pre>
  
  <p>When compiled; I get this message:</p>
  
  <pre><code>rtpl@rtpl-desktop:~/Desktop$ g++ -g checkts.cpp
  checkts.cpp: In function ‘int main()’:
  checkts.cpp:8:27: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
      char* storedfilepath = "/home/rtpl/Desktop/ts.mp4";
  </code></pre>
  
  <p>Upon execution: </p>
  
  <pre><code>rtpl@rtpl-desktop:~/Desktop$ ./a.out
  
   Opening file at /home/rtpl/Desktop/ts.mp4
  
   value of error is 0
  
   value of filedes is 3
   File opened successfully
   Now reading file
  
   value of error is 14
  
   File contents cannot be read
  End.
  </code></pre>
  
  <p>Entire gdb debug can be found <a href="http://txt.do/dlu1y" rel="nofollow noreferrer">here</a>.</p>
  
  <p>Question : Why won't the file contents be read when the file is legit and the compiler throws no error?</p>
  
  <p><a href="https://i.stack.imgur.com/7V9E0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7V9E0.png" alt="Ts.mp4"></a>
  <a href="https://i.stack.imgur.com/UpBXA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UpBXA.png" alt="permissions"></a></p>