| [683] | 1 | /* $Id: opendir.c,v 1.1 1999-12-10 17:11:26 ansari Exp $ */ | 
|---|
|  | 2 |  | 
|---|
|  | 3 | #include <stdio.h> | 
|---|
|  | 4 | #include <stdlib.h> | 
|---|
|  | 5 | #include <string.h> | 
|---|
|  | 6 | #include <errno.h> | 
|---|
|  | 7 | #include "dirent.h" | 
|---|
|  | 8 |  | 
|---|
|  | 9 | DIR *opendir(char const * path) | 
|---|
|  | 10 | { | 
|---|
|  | 11 | CInfoPBRec cipbr; | 
|---|
|  | 12 | HFileInfo *fpb = (HFileInfo*)&cipbr; | 
|---|
|  | 13 | DirInfo *dpb = (DirInfo*)&cipbr; | 
|---|
|  | 14 | DIR *dp; | 
|---|
|  | 15 | char name[FILENAME_MAX]; | 
|---|
|  | 16 | short err; | 
|---|
|  | 17 | FSSpec tempspec; | 
|---|
|  | 18 |  | 
|---|
|  | 19 | strncpy(name, path, sizeof(name)-1); | 
|---|
|  | 20 | c2pstr(name); | 
|---|
|  | 21 |  | 
|---|
|  | 22 | err = FSMakeFSSpec(0,0,(unsigned char*)name,&tempspec); | 
|---|
|  | 23 |  | 
|---|
|  | 24 | fpb->ioNamePtr= (unsigned char*)name; | 
|---|
|  | 25 | fpb->ioVRefNum= 0; | 
|---|
|  | 26 | fpb->ioFDirIndex= 0; | 
|---|
|  | 27 | fpb->ioFVersNum= 0; | 
|---|
|  | 28 | dpb->ioDrDirID= 0; | 
|---|
|  | 29 | err= PBGetCatInfo(&cipbr, FALSE); | 
|---|
|  | 30 | if (err != noErr) { | 
|---|
|  | 31 | errno = ENOENT; | 
|---|
|  | 32 | return NULL; | 
|---|
|  | 33 | } | 
|---|
|  | 34 | dp = (DIR*)calloc(1, sizeof(DIR)); | 
|---|
|  | 35 | if (dp != NULL) { | 
|---|
|  | 36 | dp->volrefnum = tempspec.vRefNum; | 
|---|
|  | 37 | dp->dirid = fpb->ioDirID; | 
|---|
|  | 38 | dp->nextfile = 1; | 
|---|
|  | 39 | } | 
|---|
|  | 40 | return dp; | 
|---|
|  | 41 | } | 
|---|
|  | 42 |  | 
|---|
|  | 43 | /* | 
|---|
|  | 44 | * Close a directory. | 
|---|
|  | 45 | */ | 
|---|
|  | 46 |  | 
|---|
|  | 47 | int closedir(DIR *dp) | 
|---|
|  | 48 | { | 
|---|
|  | 49 | free(dp); | 
|---|
|  | 50 | return 0; | 
|---|
|  | 51 | } | 
|---|
|  | 52 |  | 
|---|
|  | 53 | /* | 
|---|
|  | 54 | * Read the next directory entry. | 
|---|
|  | 55 | */ | 
|---|
|  | 56 |  | 
|---|
|  | 57 | struct dirent *readdir(DIR *dp) | 
|---|
|  | 58 | { | 
|---|
|  | 59 | CInfoPBRec cipbr; | 
|---|
|  | 60 | HFileInfo *fpb = (HFileInfo*)&cipbr; | 
|---|
|  | 61 | DirInfo *dpb = (DirInfo*)&cipbr; | 
|---|
|  | 62 | short err; | 
|---|
|  | 63 | static struct dirent dir; | 
|---|
|  | 64 |  | 
|---|
|  | 65 | fpb->ioDirID= dp->dirid; | 
|---|
|  | 66 | fpb->ioNamePtr= (unsigned char*)dir.d_name; | 
|---|
|  | 67 | fpb->ioVRefNum= dp->volrefnum; | 
|---|
|  | 68 | fpb->ioFDirIndex= dp->nextfile++; | 
|---|
|  | 69 | fpb->ioFVersNum= 0; | 
|---|
|  | 70 | err= PBGetCatInfo(&cipbr, FALSE); | 
|---|
|  | 71 | if (err != noErr) { | 
|---|
|  | 72 | errno = EIO; | 
|---|
|  | 73 | return NULL; | 
|---|
|  | 74 | } | 
|---|
|  | 75 | p2cstr((StringPtr)dir.d_name); | 
|---|
|  | 76 | dir.d_namlen = strlen(dir.d_name); | 
|---|
|  | 77 | dir.d_reclen = sizeof(dir); | 
|---|
|  | 78 | dir.d_ino = 0; | 
|---|
|  | 79 | return &dir; | 
|---|
|  | 80 | } | 
|---|
|  | 81 |  | 
|---|
|  | 82 | void rewinddir(DIR *dp) | 
|---|
|  | 83 | { | 
|---|
|  | 84 | dp->nextfile = 1; | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
|  | 87 | /* | 
|---|
|  | 88 | long telldir(DIR *dp) | 
|---|
|  | 89 | { | 
|---|
|  | 90 | return dp->nextfile; | 
|---|
|  | 91 | } | 
|---|
|  | 92 |  | 
|---|
|  | 93 | void seekdir(DIR *dp, long location) | 
|---|
|  | 94 | { | 
|---|
|  | 95 | dp->nextfile = location; | 
|---|
|  | 96 | } | 
|---|
|  | 97 | */ | 
|---|