LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   file descriptor doubt. (https://www.linuxquestions.org/questions/linux-newbie-8/file-descriptor-doubt-827931/)

avee137 08-23-2010 02:47 AM

file descriptor doubt.
 
please consider the following code:
unsigned long word;
Code:

ssize_t nr;
/* read a couple bytes into 'word' from 'fd' */
nr = read (fd, &word, sizeof (unsigned long));
if (nr == -1)
/* error */

This example reads from the file descriptor fd into word.

what does it mean when we say-"reads from the file descriptor".?
All i understand about file descriptor is that its an int value returned by open()system call.Hence the doubt:if fd is not a pointer or an address whats the meaning of saying from file descriptor.

Any relevant help would be appreciated.

chrism01 08-23-2010 03:57 AM

I/O channels are numbered as integers.
Consider the std login env

Code:

name = num
-----------

stdin = 0
stdout = 1
stderr = 2

See man page for open
Quote:

Given a pathname for a file, open() returns a file descriptor, a small,non-negative integer for use in subsequent system calls (read(2), write(2), lseek(2), fcntl(2), etc.). The file descriptor returned by a successful call will be the lowest-numbered file descriptor not currently open for the process.
By comparison, see the man pages for fopen() & fdopen().


All times are GMT -5. The time now is 01:47 AM.