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