Jan Schaumann on Nostr: One assignment I give students in my "Advanced Programming in the UNIX Environment" ...
One assignment I give students in my "Advanced Programming in the UNIX Environment" class includes reading data from a pipe into a fixed-size buffer.
A clever approach for that is
```
total = 0;
while ((n = read(fd, buf + total, len - total)) > 0)
total += n;
```
This is a common construct found (but not explained) in StackOverflow posts and different open source code bases. But it's not something students tend to come up with on their own and struggle to explain if asked.
Published at
2025-11-18 16:24:37 UTCEvent JSON
{
"id": "b5972c3db63ab5c9a5b40c2d0f8f12d1146dcc432ba9834852dd88c7cf2b059f",
"pubkey": "b3087ccfbff4c2e2e16a3af148b6a3a27fe07bb1e7628b714a11e5f26711f263",
"created_at": 1763483077,
"kind": 1,
"tags": [
[
"proxy",
"https://mstdn.social/users/jschauma/statuses/115571626940691255",
"activitypub"
],
[
"client",
"Mostr",
"31990:6be38f8c63df7dbf84db7ec4a6e6fbbd8d19dca3b980efad18585c46f04b26f9:mostr",
"wss://relay.ditto.pub/"
]
],
"content": "One assignment I give students in my \"Advanced Programming in the UNIX Environment\" class includes reading data from a pipe into a fixed-size buffer.\n\nA clever approach for that is\n\n```\ntotal = 0;\nwhile ((n = read(fd, buf + total, len - total)) \u003e 0)\n total += n;\n```\n\nThis is a common construct found (but not explained) in StackOverflow posts and different open source code bases. But it's not something students tend to come up with on their own and struggle to explain if asked.",
"sig": "da1f4a5903d8f25fec4dc516254f6b5edd08222e468fde19bf0d869a7f5df3cc96ee36b4ff51a81c4ee6cb14c06fb4befec4a56aa0a83b77226aa697721748be"
}