Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

All great ideas are controversial, or have been at one time.


devel / comp.lang.tcl / Using gets in nonblocking mode on a file not ending in a newline

SubjectAuthor
* Using gets in nonblocking mode on a file not ending in a newlineclt.to.davebr
`- Using gets in nonblocking mode on a file not ending in a newlineChristian Gollwitzer

1
Using gets in nonblocking mode on a file not ending in a newline

<5821667707147@dlp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10056&group=comp.lang.tcl#10056

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: clt.to.d...@dfgh.net
Newsgroups: comp.lang.tcl
Subject: Using gets in nonblocking mode on a file not ending in a newline
Date: Sun, 06 Nov 22 03:59:07 GMT
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <5821667707147@dlp>
Injection-Info: reader01.eternal-september.org; posting-host="68d2a0e49adf33fcd23a167e7b9954e1";
logging-data="3079623"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XlyZIHDXlcvr+nUkAVCcx"
Cancel-Lock: sha1:NlmxL5Zk6DJT+xIoxRHGx3COiOM=
 by: clt.to.d...@dfgh.net - Sun, 6 Nov 2022 03:59 UTC

After thinking about recent comments about reading CSV files, and trying a few experiments,
I noticed odd behavior when using gets in nonblocking mode on files that did not end with a newline.

The first [gets] attempting to read the last text before the end of file returned no data,
(returned -1 if a variable name was supplied) and the file was fblocked after the read attempt.
A second [gets] returned the text up to the end of file, cleared fblocked and set EOF.
Any subsequent gets returned no data (returned -1 if a variable was given) and EOF remained set.

This behavior does not appear to be explained on the gets or fconfigure man pages. Where is this documented?

transcripts from tkcon:

# create a short file with no trailing newline
(try) 57 % set ff [open no-eol.txt w]
file6
(try) 58 % puts -nonewline $ff "asdf"
(try) 59 % close $ff
(try) 60 % file size no-eol.txt
4

# gets in nonblocking mode
(try) 70 % set ff [open no-eol.txt r]
file6
(try) 71 % fconfigure $ff -blocking 0
(try) 72 % fblocked $ff
0 (try) 73 % gets $ff line
-1
# no new line after current file location, fblocked waiting for a newline to appear?
(try) 74 % fblocked $ff
1 (try) 75 % eof $ff
0 # at this point no EOF, but fblocked is true, issue another gets
(try) 76 % gets $ff line
4 # line is read up to to end of file!
(try) 77 % set line
asdf
(try) 78 % eof $ff
1 (try) 79 % fblocked $ff
0 # now at this point have EOF, nothing left to read
(try) 80 % gets $ff line
-1
(try) 81 % fblocked $ff
0 (try) 82 % eof $ff
1 # the file I/O configuration was
(try) 85 % fconfigure $ff
-blocking 0 -buffering full -buffersize 4096 -encoding utf-8 -eofchar {} -translation auto

Dave B

Re: Using gets in nonblocking mode on a file not ending in a newline

<tk83jh$330vm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10059&group=comp.lang.tcl#10059

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: aurio...@gmx.de (Christian Gollwitzer)
Newsgroups: comp.lang.tcl
Subject: Re: Using gets in nonblocking mode on a file not ending in a newline
Date: Sun, 6 Nov 2022 11:51:29 +0100
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <tk83jh$330vm$1@dont-email.me>
References: <5821667707147@dlp>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 6 Nov 2022 10:51:29 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="236d0253cef5e73f9662e8e837cdd615";
logging-data="3245046"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qTbMQY0jd0OA2LlAy2eXTHjrGqek+WjE="
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:102.0)
Gecko/20100101 Thunderbird/102.4.0
Cancel-Lock: sha1:r45Su0YL2VtGkG4tBUd6S2nrl4k=
In-Reply-To: <5821667707147@dlp>
 by: Christian Gollwitzer - Sun, 6 Nov 2022 10:51 UTC

Am 06.11.22 um 04:59 schrieb clt.to.davebr@dfgh.net:
> After thinking about recent comments about reading CSV files, and trying a few experiments,
> I noticed odd behavior when using gets in nonblocking mode on files that did not end with a newline.

non-blocking mode doesn't make much sense on a file. On a socket or
command pipe, non-blocking is useful because if the sender decides not
to send any data, you would otherwise wait infinitely long. A file is
always ready. My guess is that you actually want to do something else.

Christian

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor