{"action":"created","issue":{"url":"https://api.github.com/repos/samtools/htslib/issues/720","repository_url":"https://api.github.com/repos/samtools/htslib","labels_url":"https://api.github.com/repos/samtools/htslib/issues/720/labels{/name}","comments_url":"https://api.github.com/repos/samtools/htslib/issues/720/comments","events_url":"https://api.github.com/repos/samtools/htslib/issues/720/events","html_url":"https://github.com/samtools/htslib/issues/720","id":335578663,"node_id":"MDU6SXNzdWUzMzU1Nzg2NjM=","number":720,"title":"Equivalent of int feof(FILE *stream) for hFILE in htslib/hfile.h","user":{"login":"freeseek","id":1829330,"node_id":"MDQ6VXNlcjE4MjkzMzA=","avatar_url":"https://avatars1.githubusercontent.com/u/1829330?v=4","gravatar_id":"","url":"https://api.github.com/users/freeseek","html_url":"https://github.com/freeseek","followers_url":"https://api.github.com/users/freeseek/followers","following_url":"https://api.github.com/users/freeseek/following{/other_user}","gists_url":"https://api.github.com/users/freeseek/gists{/gist_id}","starred_url":"https://api.github.com/users/freeseek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/freeseek/subscriptions","organizations_url":"https://api.github.com/users/freeseek/orgs","repos_url":"https://api.github.com/users/freeseek/repos","events_url":"https://api.github.com/users/freeseek/events{/privacy}","received_events_url":"https://api.github.com/users/freeseek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-25T21:42:26Z","updated_at":"2018-06-26T07:49:18Z","closed_at":null,"author_association":"NONE","body":"How do you test whether you are at the end of an `hFILE`?\r\n\r\nThe simplest way I could come up is the following:\r\n```\r\nif ( hgetc(fp) != EOF ) ...\r\n```\r\n\r\nHowever, this is not ideal because it increases `fp->begin` by one. What is the most appropriate way? I thought of a couple of options:\r\n\r\n```\r\nint heof(hFILE *fp)\r\n{\r\n    return (fp->end==fp->begin) && (refill_buffer(fp)==0);\r\n}\r\n```\r\n\r\nOr the following:\r\n```\r\nint heof(hFILE *fp)\r\n{\r\n    if ( hgetc(fp) == EOF ) return 1;\r\n    fp->begin--;\r\n    return 0;\r\n}\r\n```\r\n\r\nEither way, it feels weird that `hFILE` does not have an equivalent for `int feof(FILE *stream)`."},"comment":{"url":"https://api.github.com/repos/samtools/htslib/issues/comments/400213927","html_url":"https://github.com/samtools/htslib/issues/720#issuecomment-400213927","issue_url":"https://api.github.com/repos/samtools/htslib/issues/720","id":400213927,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMDIxMzkyNw==","user":{"login":"jkbonfield","id":2210525,"node_id":"MDQ6VXNlcjIyMTA1MjU=","avatar_url":"https://avatars0.githubusercontent.com/u/2210525?v=4","gravatar_id":"","url":"https://api.github.com/users/jkbonfield","html_url":"https://github.com/jkbonfield","followers_url":"https://api.github.com/users/jkbonfield/followers","following_url":"https://api.github.com/users/jkbonfield/following{/other_user}","gists_url":"https://api.github.com/users/jkbonfield/gists{/gist_id}","starred_url":"https://api.github.com/users/jkbonfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkbonfield/subscriptions","organizations_url":"https://api.github.com/users/jkbonfield/orgs","repos_url":"https://api.github.com/users/jkbonfield/repos","events_url":"https://api.github.com/users/jkbonfield/events{/privacy}","received_events_url":"https://api.github.com/users/jkbonfield/received_events","type":"User","site_admin":false},"created_at":"2018-06-26T07:49:18Z","updated_at":"2018-06-26T07:49:18Z","author_association":"CONTRIBUTOR","body":"I was pondering this only recently.  It appears currently the way the code works if you keep reading until you get a negative result and then check if errno is non-zero via `herrno(fp)`, indicating a genuine error instead of EOF.  This isn't particularly ideal.\r\n\r\nNote hFILE struct has an `at_eof` field which is ideal for this, but while it is in the public header files it has a statement that the structure should be considered as opaque.  I'm not sure it is the same thing though, as it looks to be an indicator that the underlying stream is at eof and not necessary our buffer is at eof.  However the two combined (we're at end of buffer plus underlying buffer is at eof) would suffice.  This essentially matches your first implementation.\r\n\r\n@jmarshall wrote this code so he'll know the best route forward."}}
{"actor":{"display_login":"jkbonfield"}}