CREAT(2)

✨ CREAT(2) β€” the create-a-new-file girlie ✨

okay so bestie, welcome to section 2 of the manual (that's the system calls section, iykyk) πŸ’… and today's main character is creat β€” the function whose entire job is, and I cannot stress this enough, creating a new file. that's it. that's the vibe. πŸŽ€


πŸ“š LIBRARY

Standard C Library β€” you'll be linking against libc, a.k.a. -lc. she's everywhere, she's iconic, she's already there. 🫢


🌸 SYNOPSIS

#include <fcntl.h>

int
creat(const char *path, mode_t mode);

so you pull in the header, and you get one lil function that takes a path and a mode, and hands you back an int. slay. ✨


πŸ’– DESCRIPTION

okay so here's the tea, and it's a little bit of a jumpscare: 🫣

This interface is made obsolete by: open(2).

not me telling you that the whole function you came here to read about has been made obsolete by open(2) πŸ’€ it's giving legacy. it's giving "still here for the culture." it's giving "we keep her around because the old code is emotionally attached to her." but like, no cap, that's literally what the manpage says, so don't come for me. 😭

and the actual mechanics? creat() is the same as calling open(2) like this, exactly this:

open(path, O_CREAT | O_TRUNC | O_WRONLY, mode);

so if you were wondering what flags she's secretly passing, there they are, all three of them, right there in the open: O_CREAT (make it if it's not there), O_TRUNC (if it is there, yeet the contents to zero, no hesitation πŸ’…), and O_WRONLY (write-only, bestie, we are not reading today). she's a shortcut wrapper, an icon, a legend, and honestly kind of a fossil. πŸ¦‹


πŸ‘€ SEE ALSO

  • open(2) β€” the glow-up version, the one you should probably actually be using, the one this whole page keeps pointing at like a proud older sibling. 🫢

πŸ•°οΈ HISTORY

creat() appeared in Version 6 AT&amp;T UNIX. yes, that Version 6. she's ancient, she's vintage, she's been here since before your parents were born, and she has main character energy that simply never expired. πŸ‘‘


and that's the whole page, bestie!! πŸŽ€ thanks for reading the Debian edition of this manual page, dated June 2, 1993 β€” yes, 1993, she is a genuine vintage piece and we stan a timeless classic πŸ’– stay hydrated, link against libc, and may all your file descriptors be valid βœ¨πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from