#stdio

Felix Palmen :freebsd: :c64:zirias@bsd.cafe
2025-04-02

This, btw, was yet another reminder of the horrible can of worms #stdio's #buffering is.

I created a little tool running as a child process to do the *actual* #PAM authentication, so it will be possible to have this run as root while the real service drops all privileges. This little tool uses a simple line-based protocol for communication on stdin/stdout. It worked well when testing directly on the terminal.

On the first real test though, my service just went hanging. 🙄 I suspected a deadlock caused by pthread mutexes. Wasted quite some time looking into that. Then I finally realized communication over the pipes was stalled.

Ok, just set buffering mode to "line buffering" after fdopen'ing the #pipe. Turned out that didn't help either. I *assume* that even in the child process, the stdio streams automatically created on the pipes were somehow fully buffered. But at that point, I was really fed up with trial and error and rewrote the whole mess to do I/O using plain #POSIX APIs (read, write), sidestepping any buffering. Worked like a charm. 🙈

#C #coding

Jons Mostovojsjonn@social.doma.dev
2025-01-31

I quietly posted a practical deep-dive into #Linux #STDIO.

Please don't share this post anywhere outside of Mastodon yet, but criticise its flow and narrative structure.

It's a loaded topic, so I had to choose the things that are the most important for complete understanding of STDIO and its behaviour, with the aim of demystifying the concept.

memorici.de/posts/make-or-brea

Steven Sandersonspsanderson@rstats.me
2024-10-18

Here is a second example from the book C Absolute Beginner Guide Third Edition.

I worked through it and this stuff I have to say is starting to make some sense.

#C #CProgramming #Programming #Coding #scanf #printf #stdio

This code is like having a chat with a computer about pizza! Here's how it works, explained super simply:

1. The computer asks how much a pizza costs and you tell it by typing in a price.
2. Then it asks what your favorite pizza topping is, like "pepperoni."
3. Next, it asks how many slices of pizza you can eat.
4. After that, it wants to know today's date (like month, day, and year).
5. Finally, it takes all your answers and tells you: "On this date, you can treat yourself to [X] slices of [your topping] pizza, and it will cost you [this much money]!"

It’s like a little pizza order conversation between you and the computer!
Steven P. Sanderson II, MPHstevensanderson@mstdn.social
2024-10-18

Here is a second example from the book C Absolute Beginner Guide Third Edition.

I worked through it and this stuff I have to say is starting to make some sense.

#C #CProgramming #Programming #Coding #scanf #printf #stdio

This code is like having a chat with a computer about pizza! Here's how it works, explained super simply:

1. The computer asks how much a pizza costs and you tell it by typing in a price.
2. Then it asks what your favorite pizza topping is, like "pepperoni."
3. Next, it asks how many slices of pizza you can eat.
4. After that, it wants to know today's date (like month, day, and year).
5. Finally, it takes all your answers and tells you: "On this date, you can treat yourself to [X] slices of [your topping] pizza, and it will cost you [this much money]!"

It’s like a little pizza order conversation between you and the computer!
2024-10-05

@lattera
I'm not an OpenBSD developer, so I would be mis-understanding, but if I design the pledge functionality, maybe I would do the same.

close() is basically tied with open(), with some exceptions, stdin, stdout and stderr.
These 3 are opened on process initialization, by default for at least programs by C.

My guess (never actually used, though) with pledge is that it's not initialized on compilation time, but runtime. So the default 3 "files" are already opened when the code initializes pledge. And in some cases, any of there 3 are closed after the process starts. More, these 3 belongs to stdio. So close() should require stdio, or something it belongs to. Just corelated open() is hidden in crt1.o made it overly confusing.

Correct me if I'm mis-understanding.

#OpenBSD #pledge #close #stdio

2024-01-12

[Перевод] Оптимизируя неоптимизируемое: ускорение компиляции C++

В этой статье речь пойдёт о повышении скорости компиляции библиотеки {fmt} до уровня библиотеки ввода-вывода Cи stdio . Дня начала немного теории. {fmt} – это популярная открытая библиотека С++, представляющая более эффективную альтернативу С++ библиотеке iostreams и библиотеке Си stdio . Последнюю она обошла по целому ряду аспектов: Безопасность типов с проверками форматирующих строк во время компиляции . Эти проверки включены по умолчанию начиная с С++ 20, и присутствуют в качестве дополнения для С++ 14/17. Форматирующие строки среды выполнения в {fmt} также оказываются безопасными, чего невозможно достичь в printf . Расширяемость . Определяемый пользователем тип можно сделать форматируемым . При этом большинство типов стандартных библиотек, например, контейнеры и пакеты для обработки даты и времени, предлагают возможность форматирования изначально. Производительность . {fmt} намного быстрее любой распространённой реализации printf , порой на несколько порядков (например, в форматировании чисел с плавающей запятой ). Возможность переноса поддержки Unicode . Тем не менее одной из областей, в которой stdio по-прежнему опережала {fmt} , являлось время компиляции.

habr.com/ru/companies/ruvds/ar

#ruvds_перевод #с++ #си #fmt #стандартные_библиотеки #оптимизация #компиляция #stdio

2024-01-03

Working with data streams on the #Linux command line – David Both #stdio

both.org/?p=3101

Mattias Wadmanwader@fosstodon.org
2023-02-09

In 2023, STD I/O is an underused feature of any *NIX system, and should be considered more!

#unix #stdio #programming #scripting

2022-12-19

Oh promised #2. It was too long, shorter. Web/cloud port server straight C. Thin server wrapper straight C sockets, uses #stdio sockets and NOTHING else to talk to random language app. Thin client, straight C and sockets. x11ish commands dirt simple, tiny, no concept of buttons etc. Just clicks on x/10000 width and y/10000 width but height (ref prev utube) 2/2

Doc Edward Morbius ⭕​dredmorbius@toot.cat
2022-03-21

@alcinnz You might want to dig up some early AT&T Unix sources --- the Lion book or even the original source code as I believe almost all of it is now online.

Many of the original core utilities were really spartan as I recall, #stdio and and a syscall.

2019-05-07

#linuxcommand
#stdio
#fileio

linux コマンド tee 画面とファイルの両方へ出力
bioinfo-dojo.net/2016/08/12/co

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst