home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / library / rcs / opendir.c,v < prev    next >
Encoding:
Text File  |  1992-08-09  |  2.0 KB  |  115 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.2
  10. date    92.08.09.20.59.35;    author amiga;    state Exp;
  11. branches;
  12. next    1.1;
  13.  
  14. 1.1
  15. date    92.05.14.19.55.40;    author mwild;    state Exp;
  16. branches;
  17. next    ;
  18.  
  19.  
  20. desc
  21. @open directory file
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @add cast
  28. @
  29. text
  30. @/*
  31.  *  This file is part of ixemul.library for the Amiga.
  32.  *  Copyright (C) 1991, 1992  Markus M. Wild
  33.  *
  34.  *  This library is free software; you can redistribute it and/or
  35.  *  modify it under the terms of the GNU Library General Public
  36.  *  License as published by the Free Software Foundation; either
  37.  *  version 2 of the License, or (at your option) any later version.
  38.  *
  39.  *  This library is distributed in the hope that it will be useful,
  40.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  41.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  42.  *  Library General Public License for more details.
  43.  *
  44.  *  You should have received a copy of the GNU Library General Public
  45.  *  License along with this library; if not, write to the Free
  46.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  47.  *
  48.  *  $Id: opendir.c,v 1.1 1992/05/14 19:55:40 mwild Exp $
  49.  *
  50.  *  $Log: opendir.c,v $
  51.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  52.  *  Initial revision
  53.  *
  54.  */
  55.  
  56. #define KERNEL
  57. #include "ixemul.h"
  58. #include <sys/stat.h>
  59. #include <dirent.h>
  60.  
  61. extern void *kmalloc ();
  62.  
  63. DIR *
  64. opendir (const char *name)
  65. {
  66.   DIR *d;
  67.   int err;
  68.   struct stat stb;
  69.  
  70.   if (!(d = (DIR *) syscall (SYS_malloc, sizeof (*d)))) return 0;
  71.  
  72.   if ((d->dd_fd = syscall (SYS_open, name, 0)) >= 0)
  73.     {
  74.       if (syscall (SYS_fstat, d->dd_fd, &stb) == 0)
  75.     {
  76.       if (! S_ISDIR (stb.st_mode))
  77.         {
  78.           syscall (SYS_free, d);
  79.           errno = ENOTDIR;
  80.           return 0;
  81.         }
  82.  
  83.       return d;
  84.     }
  85.     
  86.       err = errno;
  87.  
  88.       syscall (SYS_close, d->dd_fd);
  89.     }
  90.   else
  91.     err = errno;
  92.  
  93.   syscall (SYS_free, d);
  94.   errno = err;
  95.   return 0;
  96. }
  97. @
  98.  
  99.  
  100. 1.1
  101. log
  102. @Initial revision
  103. @
  104. text
  105. @d19 1
  106. a19 1
  107.  *  $Id$
  108. d21 4
  109. a24 1
  110.  *  $Log$
  111. d41 1
  112. a41 1
  113.   if (!(d = syscall (SYS_malloc, sizeof (*d)))) return 0;
  114. @
  115.