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