title: Program gets stuck while trying to read a file using read() system call
body: <p>Here is my code snippet:</p>
  
  <pre><code>int fd;
  bufsize = 30;
  char buf[bufsize];
  char cmd[100] = "file.txt";
  int newfd = 1;
  
  if (fd = open(cmd,O_RDONLY) &gt;=0){
      puts("wanna read");
      while (read(fd,&amp;bin_buf,bufsize)==1){
          puts("reading");
          write(newfd,&amp;bin_buf,bufsize);
      }
      close(fd);
  }
  </code></pre>
  
  <p>So here the program prints <code>"wanna read"</code> but never prints <code>"reading"</code>. I have also tried opening using nonblock flag, but no use. Can anybody help me? I must use <code>open()</code> and <code>read()</code> system calls only. Thanks.
  Edit: I have made some clarifications in the code. Actually the newfd that I'm writing to is a socket descriptor, but I don't think that is important for this problem because it sticks on the <code>read</code> which is before the <code>write</code>.</p>