r/C_Programming • • Sep 12 '26

Question What C function would you delete and rewrite first, and why?

For me it's fnmatch - mostly because it's 40 year's old and smell's funny.

95 Upvotes

238 comments sorted by

View all comments

Show parent comment

1

u/musbur Sep 13 '26

yeah but a file handle is pretty much a file handle anywhere while (recursive) directory creation is conceptually something totally different.

1

u/a4qbfb Sep 13 '26

so?

1

u/musbur Sep 13 '26

C just doesn't go that deep into OS abstraction. It's a choice to keep the language simple. It also doesn't have associate arrays, linked lists, a network stack, multithreading, or an http server.

4

u/a4qbfb Sep 13 '26

C does have multithreading; none of the other features you list are OS abstractions. An implementation is absolutely free to automatically create parent directories on fopen() if it wants to, as long as it documents it.

1

u/musbur Sep 13 '26

Opening and writing to a file descriptor has nothing to do with file system structure. There's no reason to wrap unrelated concepts into a single function. Regarding multithreading, which standard introduced that? Can't find it in K&R.

5

u/a4qbfb Sep 13 '26

K&R is 48 years old and predates the ISO standard by 12 years. Multithreading was added in C11, 15 years ago. The C standard does not know about directories, so an implementation is free to do whatever it wants with them.

PS: the standard does not know about file descriptors either, only I/O streams.

0

u/flatfinger Sep 14 '26

People were writing multi-tasking code in C even before the publication of C89. A multi-tasking OS would need to have a small number of assembly-language functions, but for the most part all that was needed was to have a compiler refrain from ordering any loads or stores across volatile accesses--something commercial compilers like MSVC used to do by default, Keil can be configured to do, and gcc can't do--except at -O0, without the use of gcc-specific syntax (which ARM was designed to support).

1

u/flatfinger Sep 14 '26

Many system's file handles can't hold characters that were pushed back with ungetc.