ELFTC_SET_TIMESTAMPS(3)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’… ELFTC_SET_TIMESTAMPS(3) β€” library functions manual, bestie edition

okay so you're looking at elftc_set_timestamps from the Library Functions Manual and honestly? it's giving "small function, big main character energy." it lives in libelftc, and it does exactly one thing but it does it slayfully.

✨ NAME ✨

elftc_set_timestamps β€” set file timestamps πŸ•βœ¨

πŸŽ€ LIBRARY πŸŽ€

the library is literally libelftc, no cap. that's the one you link against, bestie β€” library β€œlibelftc”.

🌸 SYNOPSIS 🌸

#include <libelftc.h>

int
elftc_set_timestamps(const char *filename, struct stat *sb);

πŸ¦‹ DESCRIPTION πŸ¦‹

so elftc_set_timestamps() is the function you call when you want to set the access time stamp and the modified time stamp on a file, based on whatever's chillin' inside a struct stat descriptor. it's giving "copy the vibes of one file onto another," fr fr. πŸ’–

  • argument filename names an existing file in the file system. like, it has to actually exist, okay? that's the whole point.
  • argument sb points to a structure of type struct stat that was populated by a prior call to fstat(2) or stat(2). so you gotta go get the stat first, then hand it over. πŸ’…

πŸ”₯ IMPLEMENTATION NOTES πŸ”₯

this is the fun part, ngl. this function will invoke the high-resolution utimes(2) system call if the underlying operating system supports it. icon behavior. but on operating systems that are lowkey lacking support for utimes(2), the function will fall back to the lower resolution utime(2) system call instead. so like β€” same energy, slightly crunchier pixels. πŸ“Έ

no cap: which syscall you get depends entirely on what your OS supports. you don't get to pick. 🫢

πŸ’œ EXAMPLES πŸ’œ

ok so say you want to set the access time and modified time for a new file to match those of an existing file β€” literally the classic "make my file have the same timestamp as yours" move. here's the whole thing, verbatim:

struct stat sb;
const char *existing_filename, *new_filename;

if (stat(existing_filename, &sb) < 0)
        err(EXIT_FAILURE, "stat failed");

if (elftc_set_timestamps(new_filename, &sb) < 0)
        err(EXIT_FAILURE, "timestamps could not be set");

see how it stats the old one first, then stamps the new one? that's the whole plot. πŸ“

🌈 SEE ALSO 🌈


and that's the page, bestie!! 🧚✨ this one's from Debian, dated December 15, 2011, and it's page ELFTC_SET_TIMESTAMPS(3) β€” go forth and stamp those timestamps, you absolute icon πŸ‘‘πŸ’–

πŸ“¦ where this page comes from