Subversion Repositories Kolibri OS

Rev

Rev 5215 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* fstat.c -- get status of a file.
  2.  *
  3.  * Copyright (c) 1995 Cygnus Support
  4.  *
  5.  * The authors hereby grant permission to use, copy, modify, distribute,
  6.  * and license this software and its documentation for any purpose, provided
  7.  * that existing copyright notices are retained in all copies and that this
  8.  * notice is included verbatim in any distributions. No written agreement,
  9.  * license, or royalty fee is required for any of the authorized uses.
  10.  * Modifications to this software may be copyrighted by their authors
  11.  * and need not follow the licensing terms described here, provided that
  12.  * the new terms are clearly indicated on the first page of each file where
  13.  * they apply.
  14.  */
  15. #include <errno.h>
  16. #include <string.h>
  17. #include <sys/unistd.h>
  18. #include <sys/kos_io.h>
  19. #include <sys/stat.h>
  20. #include "glue.h"
  21. #include "io.h"
  22.  
  23. int
  24. _DEFUN (fstat, (fd, buf),
  25.        int fd _AND
  26.        struct stat *buf)
  27. {
  28.     fileinfo_t info;
  29.     __io_handle *ioh;
  30.  
  31.     if( (fd < 0) || (fd >=64) )
  32.     {
  33.         errno = EBADF;
  34.         return (-1);
  35.     };
  36.  
  37.     memset (buf, 0, sizeof (* buf));
  38.  
  39.     if (fd <= STDERR_FILENO)
  40.     {
  41.         buf->st_mode = S_IFCHR;
  42.         buf->st_blksize = 0;
  43.     }
  44.     else
  45.     {
  46.  
  47.         ioh = &__io_tab[fd];
  48.         get_fileinfo(ioh->name, &info);
  49.  
  50.         buf->st_mode = S_IFREG;
  51.         buf->st_blksize = 4096;
  52.         buf->st_size = info.size;
  53.     };
  54.  
  55.     return (0);
  56. }
  57.  
  58.  
  59.  
  60.