imapext-2007

view src/osdep/unix/opendir.c @ 0:ada5e610ab86

imap-2007e
author yuuji@gentei.org
date Mon, 14 Sep 2009 15:17:45 +0900
parents
children
line source
1 /* ========================================================================
2 * Copyright 1988-2006 University of Washington
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *
11 * ========================================================================
12 */
14 /*
15 * Program: Read directories
16 *
17 * Author: Mark Crispin
18 * Networks and Distributed Computing
19 * Computing & Communications
20 * University of Washington
21 * Administration Building, AG-44
22 * Seattle, WA 98195
23 * Internet: MRC@CAC.Washington.EDU
24 *
25 * Date: 16 December 1993
26 * Last Edited: 30 August 2006
27 */
29 /* Emulator for BSD opendir() call
30 * Accepts: directory name
31 * Returns: directory structure pointer
32 */
34 DIR *opendir (char *name)
35 {
36 DIR *d = NIL;
37 struct stat sbuf;
38 int fd = open (name,O_RDONLY,NIL);
39 errno = ENOTDIR; /* default error is bogus directory */
40 if ((fd >= 0) && !(fstat (fd,&sbuf)) && ((sbuf.st_mode&S_IFMT) == S_IFDIR)) {
41 d = (DIR *) fs_get (sizeof (DIR));
42 /* initialize structure */
43 d->dd_loc = 0;
44 read (fd,d->dd_buf = (char *) fs_get (sbuf.st_size),
45 d->dd_size = sbuf.st_size);
46 }
47 else if (d) fs_give ((void **) &d);
48 if (fd >= 0) close (fd);
49 return d;
50 }
53 /* Emulator for BSD closedir() call
54 * Accepts: directory structure pointer
55 */
57 int closedir (DIR *d)
58 {
59 /* free storage */
60 fs_give ((void **) &(d->dd_buf));
61 fs_give ((void **) &d);
62 return NIL; /* return */
63 }
66 /* Emulator for BSD readdir() call
67 * Accepts: directory structure pointer
68 */
70 struct direct *readdir (DIR *d)
71 {
72 /* loop through directory */
73 while (d->dd_loc < d->dd_size) {
74 struct direct *dp = (struct direct *) (d->dd_buf + d->dd_loc);
75 d->dd_loc += sizeof (struct direct);
76 if (dp->d_ino) return dp; /* if have a good entry return it */
77 }
78 return NIL; /* all done */
79 }

UW-IMAP'd extensions by yuuji