diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-02-16 14:39:40 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 1997-02-16 14:39:40 +0000 |
commit | 6c92e0b11998dc315af7602ab8f9f98c2f5d8095 (patch) | |
tree | 430497a640a72b5615674ab051945ee57e8237a1 /sys/lib/libsa/ufs.c | |
parent | c46bb180adc2f59a65168c318cc52b3f82ff858d (diff) |
opendir, readdir, closedir (define NO_READDIR, if none required)
minor fix in cd9660
only ufs working, all the others are on the list....
Diffstat (limited to 'sys/lib/libsa/ufs.c')
-rw-r--r-- | sys/lib/libsa/ufs.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/sys/lib/libsa/ufs.c b/sys/lib/libsa/ufs.c index 8adb7048477..dd41f56a9c9 100644 --- a/sys/lib/libsa/ufs.c +++ b/sys/lib/libsa/ufs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ufs.c,v 1.8 1996/12/08 15:15:58 niklas Exp $ */ +/* $OpenBSD: ufs.c,v 1.9 1997/02/16 14:39:37 mickey Exp $ */ /* $NetBSD: ufs.c,v 1.16 1996/09/30 16:01:22 ws Exp $ */ /*- @@ -679,6 +679,54 @@ ufs_stat(f, sb) return (0); } +#ifndef NO_READDIR +int +ufs_readdir(f, name) + struct open_file *f; + char *name; +{ + register struct file *fp = (struct file *)f->f_fsdata; + char *buf; + size_t buf_size; + register struct direct *dp, *edp; + int rc, namlen; + + if (name == NULL) + fp->f_seekp = 0; + else { + /* end of dir */ + if (fp->f_seekp >= fp->f_di.di_size) { + *name = '\0'; + return 0; + } + + do { + if ((rc = buf_read_file(f, &buf, &buf_size)) != 0) + return rc; + + dp = (struct direct *)buf; + edp = (struct direct *)(buf + buf_size); + while (dp < edp && dp->d_ino == (ino_t)0) + dp = (struct direct *)((char *)dp + dp->d_reclen); + fp->f_seekp += buf_size - + ((u_int8_t *)edp - (u_int8_t *)dp); + } while (dp >= edp); + +#if BYTE_ORDER == LITTLE_ENDIAN + if (fp->f_fs->fs_maxsymlinklen <= 0) + namlen = dp->d_type; + else +#endif + namlen = dp->d_namlen; + strncpy(name, dp->d_name, namlen + 1); + + fp->f_seekp += dp->d_reclen; + } + + return 0; +} +#endif + #ifdef COMPAT_UFS /* * Sanity checks for old file systems. |