1 /* $Id: dirio.c,v 1.1.1.1 2000/06/27 01:48:01 amura Exp $ */
2 /*
3 * Name: MG 2x
4 * Directory I/O routines, by Stephen Walton
5 * Version of 5-May-88
6 */
7
8 /*
9 * $Log: dirio.c,v $
10 * Revision 1.1.1.1 2000/06/27 01:48:01 amura
11 * import to CVS
12 *
13 */
14
15 #include "config.h" /* Dec. 15, 1992 by H.Ohkubo */
16
17 #ifndef NO_DIR
18
19 #include "sysdef.h"
20 #include <libraries/dosextens.h>
21 #include <exec/memory.h>
22
23 extern char MyDirName[MAXPATH], *strncat();
24
getcwd(path,len)25 char *getcwd(path, len)
26 char *path;
27 {
28 strncpy(path,MyDirName,len);
29 return path;
30 }
31
chdir(path)32 chdir(path)
33 char *path;
34 {
35 BPTR Lock(), AttemptLock, CurrentDir();
36 long PathName(), len;
37 struct FileInfoBlock *fib;
38 void *AllocMem();
39 int retval;
40
41 AttemptLock = Lock(path, ACCESS_READ);
42 if (!AttemptLock)
43 return -1;
44 fib = (struct FileInfoBlock *) AllocMem((long)
45 sizeof(struct FileInfoBlock),
46 #ifdef BUGFIX /* Dec.18,1992 by H.Ohkubo */
47 MEMF_CHIP |
48 #endif
49 MEMF_CLEAR);
50 #ifdef BUGFIX /* Dec.20,1992 by H.Ohkubo */
51 if (fib == NULL) {
52 UnLock(AttemptLock);
53 return -1;
54 }
55 #endif
56 Examine(AttemptLock, fib);
57 if (fib->fib_DirEntryType < 0) {
58 retval = -1;
59 UnLock(AttemptLock);
60 goto clean;
61 }
62 UnLock(CurrentDir(AttemptLock)); /* do the thing */
63 if (PathName(AttemptLock, MyDirName, MAXPATH/31L) == 0)
64 MyDirName[0] = '\0';
65 retval = 0; /* Success! */
66 clean:
67 FreeMem((void *) fib, (long) sizeof(struct FileInfoBlock));
68 return retval;
69 }
70 #endif
71