Re: [dwm] dmenu-input

From: Anselm R. Garbe <arg_AT_10kloc.org>
Date: Thu, 5 Oct 2006 15:23:35 +0200

On Thu, Oct 05, 2006 at 03:18:24PM +0200, Anselm R. Garbe wrote:
> On Thu, Oct 05, 2006 at 10:18:07AM +0200, Rob Manea wrote:
> > Hi,
> >
> > I just wrote a quick replacement for the shell construct in Anselm's
> > config.arg.h which feeds dmenu with a list of all executables found in
> > $PATH.
> >
> > The programm simply scans $PATH, extracts all files executable for the
> > user running the programm and outputs those files to stdout.
> >
> > Usage:
> > dmenu-input | dmenu
> >
> > If you want it sorted:
> >
> > dmenu-input | sort -u | dmenu
> >
> >
> > The small source file is attached to this message, just in case anyone
> > may find it useful.
>
#include <dirent.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>

int
main(int argc, char *argv[]) {
        int i;
        gid_t gid = getgid();
        struct dirent *dp;
        struct stat s;
        uid_t uid = getuid();
        DIR *dir;

        for(i = 0; i < argc; i++)
                if((dir = opendir(argv[i]))) {
                        fchdir(dirfd(dir));
                        do
                                if((dp = readdir(dir))
                                        && (stat(dp->d_name, &s) != -1)
                                        && S_ISREG (s.st_mode)
                                        && ((s.st_uid == uid && s.st_mode & S_IXUSR) ||
                                                (s.st_gid == gid && s.st_mode & S_IXGRP) ||
                                                (s.st_mode & S_IXOTH)))
                                        puts(dp->d_name);
                        while(dp);
                        closedir(dir);
                }
        return 0;
}

The dfd variable was useless, also removed.

-- 
 Anselm R. Garbe  ><><  www.ebrag.de  ><><  GPG key: 0D73F361
Received on Thu Oct 05 2006 - 15:23:35 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:31:51 UTC