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

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @ *  @;
  7.  
  8.  
  9. 1.1
  10. date    92.05.14.19.55.40;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @read directory file
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*
  26.  *  This file is part of ixemul.library for the Amiga.
  27.  *  Copyright (C) 1991, 1992  Markus M. Wild
  28.  *
  29.  *  This library is free software; you can redistribute it and/or
  30.  *  modify it under the terms of the GNU Library General Public
  31.  *  License as published by the Free Software Foundation; either
  32.  *  version 2 of the License, or (at your option) any later version.
  33.  *
  34.  *  This library is distributed in the hope that it will be useful,
  35.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  36.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  37.  *  Library General Public License for more details.
  38.  *
  39.  *  You should have received a copy of the GNU Library General Public
  40.  *  License along with this library; if not, write to the Free
  41.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  42.  *
  43.  *  $Id$
  44.  *
  45.  *  $Log$
  46.  */
  47.  
  48. #define KERNEL
  49. #include "ixemul.h"
  50. #include <sys/stat.h>
  51. #include <dirent.h>
  52.  
  53. struct dirent *
  54. readdir (DIR *dp)
  55. {
  56.   u_int l;
  57.  
  58.   if (! dp || dp->dd_fd < 0) return 0;
  59.  
  60.   if (syscall (SYS_read, dp->dd_fd, 
  61.            & dp->dd_ent.d_fileno, 4) <= 0)
  62.     return 0;
  63.     
  64.   if (syscall (SYS_read, dp->dd_fd, &l, 4) <= 0)
  65.     return 0;
  66.  
  67.   /* since we don't know, whether the name is zero padded, provide a dummy */
  68.   dp->dd_ent.d_name[l] = 0;
  69.   if (syscall (SYS_read, dp->dd_fd, dp->dd_ent.d_name, l) <= 0)
  70.     return 0;
  71.  
  72.   dp->dd_ent.d_namlen = l;
  73.   /* if the name was stored without terminating zero, account for the additional
  74.    * byte in the name length field */
  75.   if (dp->dd_ent.d_name [l-1])
  76.     dp->dd_ent.d_namlen ++;
  77.   dp->dd_ent.d_reclen = l + 8;
  78.   dp->dd_ent.d_namlen--;    /* don't count zero pad */
  79.   return & dp->dd_ent;
  80. }
  81. @
  82.