Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fseek for fd (int fd instead of FILE*)

Tags:

c

file

Is there an equivalent of fseek for fd? I've been using int fds for a very long time, and want to use fseek... but I know there is no seek function.

Thanks in advance!

like image 806
Cenoc Avatar asked Dec 10 '10 05:12

Cenoc


People also ask

Does Fopen return file descriptor?

Normal returnIf successful, the fileno function returns the file descriptor number associated with an open stream (that is, one opened with the fopen , fdopen , or freopen functions).

What is FD in write?

fd is not a valid file descriptor or is not open for writing. fd refers to a datagram socket for which a peer address has not been set using connect(2). The user's quota of disk blocks on the file system containing the file referred to by fd has been exhausted. buf is outside your accessible address space.

What will be the value of the first file descriptor you will get after opening a new file with open?

So first unused file descriptor is 3 in file descriptor table. After that in close() system call is free it this 3 file descriptor and then after set 3 file descriptor as null. So when we called second open(), then first unused fd is also 3.

What is a file descriptor in Linux?

A file descriptor is an unsigned integer used by a process to identify an open file. The number of file descriptors available to a process is limited by the /OPEN_MAX control in the sys/limits. h file. The number of file descriptors is also controlled by the ulimit -n flag.


1 Answers

See the POSIX function lseek(2):

SYNOPSIS

#include <unistd.h>

off_t
lseek(int fildes, off_t offset, int whence);

DESCRIPTION

The lseek() function repositions the offset of the file descriptor fildes to the argument offset, according to the directive whence. The argument fildes must be an open file descriptor.

like image 144
John Kugelman Avatar answered Sep 27 '22 18:09

John Kugelman