Comments (1)
ringbuf_findchr
returns ringbuf_bytes_used
when there is no match, so it only returns 0
when the ring buffer is empty. (If the ring buffer is not empty and there is no match, then the value returned will be > 0
.)
It is expected that you will compare the value returned by ringbuf_findchr
to the value returned by ringbuf_bytes_used
to determine whether a match has been found, e.g.:
https://github.com/dhess/echoev/blob/c74ff579483e3aab5e10b088ef0ba63445dac0bf/echoevc.c#L337
If you compare the two values with <
, then there is no ambiguity.
The reason that ringbuf_findchr
returns ringbuf_bytes_used
when there is no match, rather than returning -1
or some other sentinel value, is so that the type of the returned value can be size_t
rather than ssize_t
; and the reason for that is for type safety, since ringbuf_findchr
itself takes size_t
offset values. (Negative offsets make no sense.)
So while this convention is slightly clumsier and a bit more expensive than checking for -1
(because this convention requires an additional call to ringbuf_bytes_used
), I think it's worth the type safety.
However, in retrospect, this is all a bit confusing, and I should probably make a note of this convention in the documentation.
from c-ringbuf.
Related Issues (9)
- Fuzz with AFL
- Add Nix support
- Is this library thread safe? HOT 5
- MIN function is undefined? HOT 4
- Can you add a simple example for using this little library HOT 2
- Missing ssize_t under Visual Studio HOT 1
- conflicting declaration 'typedef struct ringbuf_t * ringbuf_t:; HOT 5
- Consider dual licensing aside of CC0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c-ringbuf.