Skip to content

Instantly share code, notes, and snippets.

@dvdfreitag
Created May 8, 2018 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvdfreitag/87a17a59a6f78843b10528c73f7f123e to your computer and use it in GitHub Desktop.
Save dvdfreitag/87a17a59a6f78843b10528c73f7f123e to your computer and use it in GitHub Desktop.
#include <errno.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
void print_usage(void)
{
printf("Usage: blksize DIRECTORY\n");
printf("Attempts to determine the optimal block size using stat\n");
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
print_usage();
return 1;
}
struct stat stats;
int rc = stat(argv[1], &stats);
if (rc != 0)
{
printf("Error: %s\n\n", strerror(errno));
print_usage();
return rc;
}
printf("%ld\n", stats.st_blksize);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment