Skip to content

Commit

Permalink
Use the handy GNU extension to check the program's short name.
Browse files Browse the repository at this point in the history
Besides making the code cleaner, it also deals with busybox's symlink
shenanigans automagically.
  • Loading branch information
NiLuJe committed Oct 10, 2019
1 parent f9d296c commit bd22086
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions kobo-dotfile-hack/hidedir.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <syslog.h>
#include <unistd.h>

// NOTE: GNU extension!
extern char* program_invocation_short_name;

#define constructor __attribute__((constructor))

static bool wrap = true;
Expand Down Expand Up @@ -40,11 +43,7 @@ static char* dirpaths[1024] = { 0 }; // Linux default is 102
static bool
isproc(const char* proc)
{
char buf[PATH_MAX] = { 0 };
if (readlink("/proc/self/exe", buf, PATH_MAX) != -1) {
return strcmp(strrchr(buf, '/') + 1, proc) == 0;
}
return false;
return strcmp(program_invocation_short_name, proc) == 0;
}
#endif

Expand Down

0 comments on commit bd22086

Please sign in to comment.