X-Git-Url: https://gapil.gnulinux.it/gitweb/?p=gapil.git;a=blobdiff_plain;f=sources%2FDirScan.c;fp=sources%2FDirScan.c;h=0000000000000000000000000000000000000000;hp=4b3f0610ab685119ea8bd2a1efd753e7607b19fd;hb=d12bc3e1e4b3ee762036d1c226c3b2ba1a720fb9;hpb=e3e15ed6d698e5cc35f3b7f4c5db96adc38255c3 diff --git a/sources/DirScan.c b/sources/DirScan.c deleted file mode 100644 index 4b3f061..0000000 --- a/sources/DirScan.c +++ /dev/null @@ -1,65 +0,0 @@ -/* DirScan.c - * - * Copyright (C) 2002 Simone Piccardi - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -/***************************************************************************** - * - * File DirScan.c: routine for directory scan - * - * Author: S. Piccardi Jan. 2003 - * - * $Id: DirScan.c,v 1.2 2003/01/04 17:24:30 piccardi Exp $ - * - *****************************************************************************/ -#include -#include -#include /* directory */ -#include /* C standard library */ -#include -#include - -/* - * Function DirScan: - * - * Scan all entries in a directory, executing the provided function - * on each one. - * - * Input: the directory name and a computation function - * Return: 0 if OK, -1 on errors - */ -int DirScan(char * dirname, int(*compute)(struct dirent *)) -{ - DIR * dir; - struct dirent *direntry; - int fd; - - if ( (dir = opendir(dirname)) == NULL) { /* oper directory */ - printf("Opening %s\n", dirname); /* on error print messages */ - perror("Cannot open directory"); /* and then return */ - return -1; - } - fd = dirfd(dir); /* get file descriptor */ - fchdir(fd); /* change directory */ - /* loop on directory entries */ - while ( (direntry = readdir(dir)) != NULL) { /* read entry */ - if (compute(direntry)) { /* execute function on it */ - return -1; /* on error return */ - } - } - closedir(dir); - return 0; -}