FILES(3pub)
β¨ FILES(3pub) β file manipulation utilities, but make it cute β¨
okay bestie, listen up π this is the FILES page from the C Programmer's Manual (yes, that C Programmer's Manual, the publib one, iykyk) and it's literally all about messing with files. no cap.
πΈ NAME πΈ
xgetaline, xfseek, xfopen, xfclose, getaline, fassert β file manipulation utilities π
β¨ SYNOPSIS β¨
#include <files.h>
FILE *xfopen(const char *filename, const char *mode);
void xfclose(FILE *fp);
void xfseek(FILE *fp, long offset, int origin);
char *getaline(FILE *fp);
char *xgetaline(FILE *fp);
void fassert(FILE *fp);
look at that lineup. iconic. π
π DESCRIPTION π
so these functions are, like, useful for file manipulation. that's the whole vibe. π
here's the tea on the x girlies: the functions that begin with x work exactly like the functions without that letter β except if there's an error, they print an error message and kill the program. like, straight up. no chill. π so xfopen is fopen but with main character energy and zero tolerance.
π¦ getaline π¦
getaline reads a line from the given file. it allocates the memory for the line with malloc(3), and returns a pointer to the beginning of the line. if there's an error, it returns NULL.
bestie if the returned value is not NULL, the caller is responsible for freeing the memory. that's on you. don't forget or it's a leak and we don't do leaks in this house π«Ά
also the newline gets removed from the end of the line. so clean. so fresh. β¨
π fassert π
fassert checks that the argument is not NULL, and that (for a non-NULL argument) the file does not have its error indicator flag set. if either condition is true, it prints an error message and terminates the program π. if neither condition is true, it does nothing. literally nothing. silent. respectful. π
so what's it for? it's for adding checks that the I/O in a program is going well. but ngl, it's mostly useful only for small programs, because more serious programs need to handle the errors more gracefully. fr fr. the little guys get fassert, the big guys gotta cope. π
π SEE ALSO π
go read that one too, bestie, it's the whole family π«Ά
π AUTHOR π
Lars Wirzenius (lars.wirzenius@helsinki.fi) β the icon, the legend, the one who wrote this π
π that's the whole page! no notes! slay! π
and that's a wrap on the Publib edition of the C Programmer's Manual page FILES(3pub) β shoutout to publib for the vibes, mwah, periodt β¨ππ¦
π¦ where this page comes from
- debian bookworm: publib-dev 0.40-3+b1 Β· BSD-2-Clause
- debian trixie: publib-dev 0.40-4 Β· BSD-2-Clause
- ubuntu jammy: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu noble: publib-dev 0.40-3build1 Β· BSD-2-Clause
- ubuntu questing: publib-dev 0.40-4
- ubuntu resolute: publib-dev 0.40-4build1 Β· BSD-2-Clause
- ubuntu stonking: publib-dev 0.40-4build1 Β· BSD-2-Clause
- Copyright (c) 1994-2006 Lars Wirzenius. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms