1 /* Copyright 1998-2002,2009 Alain Knaff.
2 * This file is part of mtools.
4 * Mtools is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Mtools is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Mtools. If not, see <http://www.gnu.org/licenses/>.
18 #include "sysincludes.h"
28 typedef struct Dir_t {
34 struct MT_STAT statbuf;
42 /*#define FCHDIR_MODE*/
44 static int get_dir_data(Stream_t *Stream, time_t *date, mt_size_t *size,
45 int *type, int *address)
50 *date = This->statbuf.st_mtime;
52 *size = (mt_size_t) This->statbuf.st_size;
60 static int dir_free(Stream_t *Stream)
69 static Class_t DirClass = {
83 int unix_dir_loop(Stream_t *Stream, MainParam_t *mp);
84 int unix_loop(Stream_t *Stream, MainParam_t *mp, char *arg,
87 int unix_dir_loop(Stream_t *Stream, MainParam_t *mp)
97 fd = open(".", O_RDONLY);
98 if(chdir(This->pathname) < 0) {
99 fprintf(stderr, "Could not chdir into %s (%s)\n",
100 This->pathname, strerror(errno));
104 while((entry=readdir(This->dir)) != NULL) {
107 if(isSpecial(entry->d_name))
110 newName = malloc(strlen(This->pathname) + 1 +
111 strlen(entry->d_name) + 1);
116 strcpy(newName, This->pathname);
117 strcat(newName, "/");
118 strcat(newName, entry->d_name);
120 newName = entry->d_name;
122 ret |= unix_loop(Stream, mp, newName, 0);
129 perror("Could not chdir back to ..");
135 Stream_t *OpenDir(Stream_t *Stream, const char *filename)
141 This->Class = &DirClass;
145 This->pathname = malloc(strlen(filename)+1);
146 if(This->pathname == NULL) {
150 strcpy(This->pathname, filename);
152 if(MT_STAT(filename, &This->statbuf) < 0) {
153 Free(This->pathname);
158 This->dir = opendir(filename);
160 Free(This->pathname);
165 return (Stream_t *) This;