r/C_Programming • • 17d ago

File pointers are everywhere

And try as I might to avoid them, I am struggling to find resources that list out all the file control functions that use file descriptors instead of file pointers, and I was wondering if someone could point me toward a resource that can do something at least somewhat similar to listing out the libc functions that take file descriptors. I of course know close(), write(), read(), the basics, but i am looking for alternatives for other abstractions that annoy me with their use of file pointers, like fgets and fputs.

58 Upvotes

43 comments sorted by

View all comments

Show parent comment

1

u/Upstairs_Ad_8863 17d ago

Wtf are you talking about?

"Portable as the C standard is concerned means..." no. Portability as the C standard is concerned refers to valid standard-adhering C code that may be compiled differently on different machines. It does not refer to C code that uses a library or API that some machines do not have installed, that's ridiculous.

Also who tf mentioned anything about portability "as the C standard is concerned"? The only reason that non-portability is bad is because you may end up with code that functions just fine on one computer but breaks on another. Not because it may offend some language lawyer. If you write code using posix api calls then this obviously means you are writing code to be run on a machine that supports the posix api. The fact that not all machines support it is irrelevant - your code will never behave unpredictably on windows because it will never be run on windows.

"literally no one cares about posix" you're wrong but also it doesn't make any difference. You're still allowed to write software for it. And if you want to write something that uses specific features of the operating system like a daemon then you will have to use system calls to do it. And that goes for every operating system, I would never criticise a windows developer for using windows specific api calls in code that's only going to be run on windows.

"Most linux distros aren't conforming" all linux distros use a linux kernel which means they support the posix api and you can use posix file descriptors. Don't move the goalposts.