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&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
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1989, 1990, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms