chiark / gitweb /
Play catchup with Apple dscl's API churn
[disorder] / plugins / fs.c
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2004 Richard Kettlewell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20
21#include <config.h>
22
23#include <string.h>
24#include <stdlib.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <syslog.h>
28#include <errno.h>
29#include <dirent.h>
30#include <stdio.h>
31#include <unistd.h>
32
33#include <disorder.h>
34
35void disorder_scan(const char *path) {
36 struct stat sb;
37 DIR *dp;
38 struct dirent *de;
39 char *np;
40
41 if(stat(path, &sb) < 0) {
ac06ceb3 42 disorder_error(errno, "cannot stat %s", path);
460b9539 43 return;
44 }
460b9539 45 if(S_ISDIR(sb.st_mode)) {
46 if(!(dp = opendir(path))) {
47 disorder_error(errno, "cannot open directory %s", path);
48 return;
49 }
50 while((errno = 0),
51 (de = readdir(dp))) {
52 if(de->d_name[0] != '.') {
53 disorder_asprintf(&np, "%s/%s", path, de->d_name);
54 disorder_scan(np);
55 }
56 }
57 if(errno)
58 disorder_error(errno, "error reading directory %s", path);
59 closedir(dp);
ac06ceb3
RK
60 } else if(S_ISREG(sb.st_mode)) {
61 if(access(path, R_OK) < 0) {
62 disorder_error(errno, "cannot access file %s", path);
63 return;
64 }
460b9539 65 if(printf("%s%c", path, 0) < 0)
66 disorder_fatal(errno, "error writing to scanner output pipe");
ac06ceb3 67 }
460b9539 68}
69
70int disorder_check(const char attribute((unused)) *root, const char *path) {
71 if(access(path, R_OK) == 0)
72 return 1;
73 else if(errno == ENOENT)
74 return 0;
75 else {
76 disorder_error(errno, "cannot access %s", path);
77 return -1;
78 }
79}
80
81/*
82Local Variables:
83c-basic-offset:2
84comment-column:40
85End:
86*/