Package: moreutils
Version: 0.45
Followup-For: Bug #385069

Hi,
cause there didn't happen something to this topic for some years i just made a 
beginning. :)

Greetings,
Michael

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (700, 'testing'), (650, 'unstable'), (600, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 3.1.0-1-686-pae (SMP w/2 CPU cores)
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages moreutils depends on:
ii  libc6            2.13-21 
ii  libipc-run-perl  0.90-1  
ii  perl             5.14.2-5

moreutils recommends no packages.

Versions of packages moreutils suggests:
ii  libtime-duration-perl  <none>  
ii  libtimedate-perl       1.2000-1

-- no debconf information
/*
 *  dirempty.c - checks if a dir is empty
 *
 *  Copyright ©  2011  Michael Stummvoll
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  version 2 as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

void usage() {
        printf("Usage: dirempty <dirname>\n");
        printf("  returncodes:\n");
        printf("    0 - dir is empty\n");
        printf("    1 - dir is not empty\n");
        printf("    2 - wrong usage\n");
        printf("    3 - error opening directory\n");
        exit(2);
}

int main (int argc, char *argv[]) {
        int notempty = 0;
        DIR *dp;
        struct dirent *ep;
        char * dirname;

        if(argc == 2) {
                dirname = argv[1];
        } else {
                usage();
        }

        dp = opendir (dirname);
        if (dp != NULL) {
                while (ep = readdir (dp)) {
                        if(
                                strcmp(ep->d_name, ".") != 0 &&
                                strcmp(ep->d_name, "..") != 0 
                        ) {
                                notempty = 1;
                        }
                }
                closedir (dp);
        } else {
                perror ("Couldn't open the directory");
                return 3;
        }

        return notempty;
}

Reply via email to