From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: NEED HELP with "_read()" Date: Sat, 07 Dec 1996 15:01:48 -0800 Organization: Alcyone Systems Lines: 34 Message-ID: <32A9F75C.3BA286EE@alcyone.com> References: <58cqjf$6ie AT News DOT Dal DOT Ca> NNTP-Posting-Host: newton.alcyone.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Graham Howard Wile wrote: > In the "libc" documentation file, it tells how to use "_read()" > by showing that you need to feed it these parameters: > > size_t _read(int fildes, void *buf, size_t nbyte); > > The parameter I am having trouble with is the "int fildes". In > the example in the file "libc" they write: > > int r = read(0, buf, 10); fildes stands for "file descriptor." There are two traditional ways of accessing streams in C: through file descriptors, or through FILE pointers. (Both end up being the same fundamental thing, obviously, but we're talking at the interface level here.) Whenever you make a call to an I/O function to manipulate the stream, you need to pass in the file indicator -- whether or not it's a file descriptor (an int) or a pointer to a FILE structure. What's happening is that you're mixing and matching file descriptors and FILE records. You should be using fread (and the other f... functions), not read. Also, the first few file descriptors are reserved for streams which are considered always open. File descriptor 0 means stdin :-). -- Erik Max Francis | max AT alcyone DOT com Alcyone Systems | http://www.alcyone.com/max/ San Jose, California | 37 20 07 N 121 53 38 W &tSftDotIotE | R^4: the 4th R is respect "But since when can wounded eyes see | If we weren't who we were"