REMOVE(3POSIX)

πŸ’– REMOVE(3POSIX) β€” the POSIX Programmer's Manual page, but make it cute πŸ’–

okay bestie, so this page lives in the POSIX Programmer's Manual (yes, the real one, REMOVE(3POSIX)), and I'm about to give you the whole thing with the vibe it deserves. no skips, no "tl;dr", we're going the whole way 🫢


🌸 PROLOG 🌸

so like, heads up before we even start: this manual page is part of the POSIX Programmer's Manual. the Linux implementation of this interface may differ β€” like, actually differ β€” so go consult the corresponding Linux manual page for the deets on Linux behavior. orrrr the interface might not even be implemented on Linux at all. fun! πŸ™ˆ that's just how it is.


✨ NAME ✨

remove β€” remove a file. that's it. that's the whole name section. iconic brevity.


πŸŽ€ SYNOPSIS πŸŽ€

#include <stdio.h>

int remove(const char *path);

look at that. clean. gorgeous. path is a const char *, the return type is int, and the header is <stdio.h> β€” not <unistd.h>, not <stdlib.h>, <stdio.h. remember that, it's giving "surprise, file removal lives with the I/O girlies" πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

first things first, and this is important: the functionality described on this reference page is aligned with the ISO C standard. if there's any conflict between the requirements described here and the ISO C standard, that conflict is unintentional β€” nobody did that on purpose. and this volume of POSIX.1‐2017 defers to the ISO C standard. so like, ISO C is the authority here, we're just vibing alongside it. πŸ‘‘

now, what does remove() actually do? it shall cause the file named by the pathname pointed to by path to be no longer accessible by that name. poof. gone from that name. and a subsequent attempt to open that file using that name shall fail β€” unless it is created anew. (so if you make it again, it exists again. the name is free real estate. 🌈)

here's the split that matters, and it's lowkey the whole personality of this function:

  • if path does not name a directory, then remove(path) shall be equivalent to unlink(path).
  • if path does name a directory, then remove(path) shall be equivalent to rmdir(path).

so it's like a little switchboard β€” file, directory, whichever, remove() picks the right call for you. main character energy fr fr πŸ¦‹


πŸ”₯ RETURN VALUE πŸ”₯

bestie, this section has exactly one job and it's to point you elsewhere: refer to rmdir() or unlink(). that's the whole thing. go read those. 😌


πŸ’€ ERRORS πŸ’€

same deal: refer to rmdir() or unlink(). the errors are whatever those two say they are. no new lore here.

and then, the little note that closes it out: the following sections are informative. yep β€” everything after this point is informative, not normative. keep that in mind for the rest of the page. ⭐


🌟 EXAMPLES 🌟

🌷 Removing Access to a File 🌷

okay so the example is literally called "Removing Access to a File" and it shows you how to remove access to a file named /home/cnd/old_mods. here's the code, verbatim, because we do not touch code in this house:

#include <stdio.h>

int status;
...
status = remove("/home/cnd/old_mods");

see that ...? that's you, living your life, doing your thing, and then boom β€” status = remove("/home/cnd/old_mods"); and the name is free. status catches whatever comes back. slay. ✨


🌈 APPLICATION USAGE 🌈

None.

literally. that's the section. nothing to add, no notes, perfect, periodt. πŸ’…


🧚 RATIONALE 🧚

None.

the rationale girlies took the day off. honestly? respect. πŸŽ€


πŸ“ FUTURE DIRECTIONS πŸ“

None.

no plans, no drama, no upcoming changes. the future is a blank little canvas and remove() is not on it. 😌


πŸ‘‘ SEE ALSO πŸ‘‘

  • rmdir()
  • unlink()

and also! The Base Definitions volume of POSIX.1‐2017, <stdio.h> β€” that's where the header lives, go say hi. 🌸


okay legal bestie moment, gotta say it properly:

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

and also this lil disclaimer: any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. to report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! from the IEEE/The Open Group, 2017 girlies who brought you REMOVE(3POSIX) β€” mwah, go forth and remove() responsibly πŸ«ΆπŸ’…βœ¨