imapext-2007
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/osdep/unix/opendir.c Mon Sep 14 15:17:45 2009 +0900 1.3 @@ -0,0 +1,79 @@ 1.4 +/* ======================================================================== 1.5 + * Copyright 1988-2006 University of Washington 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * 1.14 + * ======================================================================== 1.15 + */ 1.16 + 1.17 +/* 1.18 + * Program: Read directories 1.19 + * 1.20 + * Author: Mark Crispin 1.21 + * Networks and Distributed Computing 1.22 + * Computing & Communications 1.23 + * University of Washington 1.24 + * Administration Building, AG-44 1.25 + * Seattle, WA 98195 1.26 + * Internet: MRC@CAC.Washington.EDU 1.27 + * 1.28 + * Date: 16 December 1993 1.29 + * Last Edited: 30 August 2006 1.30 + */ 1.31 + 1.32 +/* Emulator for BSD opendir() call 1.33 + * Accepts: directory name 1.34 + * Returns: directory structure pointer 1.35 + */ 1.36 + 1.37 +DIR *opendir (char *name) 1.38 +{ 1.39 + DIR *d = NIL; 1.40 + struct stat sbuf; 1.41 + int fd = open (name,O_RDONLY,NIL); 1.42 + errno = ENOTDIR; /* default error is bogus directory */ 1.43 + if ((fd >= 0) && !(fstat (fd,&sbuf)) && ((sbuf.st_mode&S_IFMT) == S_IFDIR)) { 1.44 + d = (DIR *) fs_get (sizeof (DIR)); 1.45 + /* initialize structure */ 1.46 + d->dd_loc = 0; 1.47 + read (fd,d->dd_buf = (char *) fs_get (sbuf.st_size), 1.48 + d->dd_size = sbuf.st_size); 1.49 + } 1.50 + else if (d) fs_give ((void **) &d); 1.51 + if (fd >= 0) close (fd); 1.52 + return d; 1.53 +} 1.54 + 1.55 + 1.56 +/* Emulator for BSD closedir() call 1.57 + * Accepts: directory structure pointer 1.58 + */ 1.59 + 1.60 +int closedir (DIR *d) 1.61 +{ 1.62 + /* free storage */ 1.63 + fs_give ((void **) &(d->dd_buf)); 1.64 + fs_give ((void **) &d); 1.65 + return NIL; /* return */ 1.66 +} 1.67 + 1.68 + 1.69 +/* Emulator for BSD readdir() call 1.70 + * Accepts: directory structure pointer 1.71 + */ 1.72 + 1.73 +struct direct *readdir (DIR *d) 1.74 +{ 1.75 + /* loop through directory */ 1.76 + while (d->dd_loc < d->dd_size) { 1.77 + struct direct *dp = (struct direct *) (d->dd_buf + d->dd_loc); 1.78 + d->dd_loc += sizeof (struct direct); 1.79 + if (dp->d_ino) return dp; /* if have a good entry return it */ 1.80 + } 1.81 + return NIL; /* all done */ 1.82 +}