Skip to content

Instantly share code, notes, and snippets.

@SteelPangolin
Created October 2, 2012 23:48
Show Gist options
  • Save SteelPangolin/3824051 to your computer and use it in GitHub Desktop.
Save SteelPangolin/3824051 to your computer and use it in GitHub Desktop.
lsflags: complementary utility to chflags. List flags for Mac OS X files and folders.
// compile with gcc -std=c99 -Wall lsflags.c -o lsflags
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <unistd.h>
#include <sys/stat.h>
bool printflags(const char *path);
int main(int argc, char **argv)
{
if (argc < 2)
{
fprintf(stderr, "usage: lsflags [path] [...]\n");
return EXIT_SUCCESS;
}
bool errors = false;
for (int i = 1; i < argc; ++i)
{
errors |= printflags(argv[i]);
}
return errors ? EXIT_FAILURE : EXIT_SUCCESS;
}
bool printflags(const char *path)
{
struct stat st;
int err = stat(path, &st);
if (err)
{
perror(path);
return true;
}
char *flagstr = fflagstostr(st.st_flags);
printf("%s: %s\n", path, flagstr);
free(flagstr);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment