title: convert between FILE type and filedescriptor in C
body: <p>LANG: C  \  OS: Linux</p>
  
  <p>I am writing a streaming program, I already implemented Play, stop and pause functionlities, when I came to implement seek, I got into the following problem and I got stuck.</p>
  
  <p>For opening the file before streaming I am using the following method:</p>
  
  <pre><code>int transport_fd = open(tsfile, O_RDONLY);
  if(transport_fd &lt; 0) 
                  {
                      fprintf(stderr, "can't open file %s\n", tsfile);
                      close(sockfdstr); // using this to stream 
                  }
  // .....
  //.....
  len = read(transport_fd, send_buf, packet_size); // here, the read function takes fd as a first argument.
  </code></pre>
  
  <p>To use <strong>fseek()</strong> function, I should pass a <em>pointer</em> of type <em>FILE</em> as an opened file to seek into, i.e pass a file pointer to the already <strong>opened</strong> stream, so how should I handle this?</p>
  
  <p>Sample dummy code:</p>
  
  <pre><code>FILE *fp;
  {CODE TO CONVERT BETWEEN *fp AND tsfd - OR ANY OTHER FIX TO THIS SITUATION}
  tsfd = fseek(fp, offset, SEEK_CUR);
  len = read(tsfd, send_buf, packet_size);
  </code></pre>