From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,df854b5838c3e14 X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,df854b5838c3e14 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,df854b5838c3e14 X-Google-Attributes: gid103376,public X-Google-Thread: 10db24,fec75f150a0d78f5 X-Google-Attributes: gid10db24,public From: Tom Wheeley Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada) Date: 1996/04/11 Message-ID: <829194658snz@tsys.demon.co.uk>#1/1 X-Deja-AN: 146968014 x-nntp-posting-host: tsys.demon.co.uk references: <828964950snz@genesis.demon.co.uk> <4kbuebINNrho@keats.ugrad.cs.ubc.ca> <4kets3$ic0@news-s01.ny.us.ibm.net> x-sig-by: Tomsystems Quote v1.2. (c)1996 Tom Wheeley, tomw@tsys.demon.co.uk x-mail2news-path: tsys.demon.co.uk organization: City Zen FM reply-to: tomw@tsys.demon.co.uk newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.edu Date: 1996-04-11T00:00:00+00:00 List-Id: In article <4kets3$ic0@news-s01.ny.us.ibm.net> mshan@ibm.net "Mike Shannon" writes: > In , dewar@cs.nyu.edu (Robert Dewar) writes: > > >There are two possible semantics that ould > >be defined for read (buffer must be at least size of the read argument, > >or buffer must be at least size of data read). Both are easy to specify, > >both are easy to implement. You cannot rely on common sense > > ... > > I'm a latecomer to this dispute, but this is not smart: > > char buf[100]; > > read(fd,buf,1000); > > Common sense, which tells me not to do such things, is a welcome ally. Certainly, but if I have been following this correctly, the 1000 is a red herring which casts doubt on the programmers ability. f.e., what if some rogue process (or kernel!) manages to increase that files size to 680 bytes? The last argument to read is your friend. :-) If you know your file will be always 68 bytes, then put 68 there. Even better, as I assume you are putting in the 1000 as a catchall for expansion, put a #define in, and base the size of your buffer, and the last argument to read on that. Simple and effective. What Robert is complaining about is that he is reading a 68 byte file by requesting 1000 bytes; and that in his opinion, read should stop reading at the end of the file, and return control. Myself, I would see this auto-stop idea as a _feature_ of read(). features can only be relied upon portably if they are positively documented in POSIX. This feature is not therefore portable, as POSIX is muddy on the matter. I suppose in c.l.c speak, it would be called `implementation-defined'. .splitbung -- * TQ 1.0 * The 'Just So Quotes'. If you keep saying things are going to be bad, you have a chance of being a prophet. -- Isaac Bashevis Singer