home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * IsDir
- *
- * Confirms that the specified path is a directory.
- *
- * Copyright 1990 by J. Gregory Noel, All Rights Reserved.
- */
-
- #include <libraries/dos.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "protos.h"
- #include "version.h"
-
- IDENT(".01");
-
- Prototype int IsDir(const char *);
-
- /*
- * The fib must be longword aligned and thus cannot be allocated
- * on the stack or statically.
- */
-
- int
- IsDir(const char *path)
- {
- BPTR lock;
- struct FileInfoBlock *fib;
- int r = 0;
-
- if (fib = malloc(sizeof(struct FileInfoBlock))) {
- if (lock = Lock(path, ACCESS_READ)) {
- if (Examine(lock, fib)) {
- if (fib->fib_DirEntryType > 0)
- r = 1;
- }
- UnLock(lock);
- }
- free(fib);
- }
- return(r);
- }
-
- #ifdef TEST
- extern int main(int argc, char **argv);
- main(int argc, char **argv)
- {
- char command[100];
-
- if (argc < 2) while (gets(command)) {
- printf("IsDir(%s) returned %d\n", command, IsDir(command));
- } else while (*++argv != NULL) {
- printf("IsDir(%s) returned %d\n", *argv, IsDir(*argv));
- }
- return 0;
- }
-
- #endif
-
-
-