Newer
Older
ubixos / src / sys / ubixfs / file.c
@reddawg reddawg on 29 Jun 2002 1 KB Fixing Problems
/**************************************************************************************
 Copyright (c) 2002 The UbixOS Project
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification,
 are prohibited.

 $Id$

**************************************************************************************/

#include <ubixfs/file.h>
#include <ubixfs/ubixfs.h>
#include <drivers/video.h>

struct fileDescriptorTable fdTable[maxFd];

int sprintf(char *buf,const char *fmt, ...);

int fclose(int fd) {
  fdTable[fd].status = fdAvail;
  return(0);
  }

int feof(int fd) {
  if (fdTable[fd].status == fdEof) {
    return(-1);
    }
  else {
    return(0);
    }
  }

int fopen(char *file,int mode) {
  int i=0;
  for (i=0;i<maxFd;i++) {
    if (fdTable[i].status == fdAvail) {
      kprintf("fd avail\n");
      sprintf(fdTable[i].fileName,"%s",file);
      findFile(fdTable[i].fileName,&fdTable[i]);
      kprintf("found file\n");
      fdTable[i].mode = mode;
      fdTable[i].status = fdOpen;
      fdTable[i].offset = 0;
      return(i);
      }
    }
  return(-1);
  }

int fgetc(int fd) {
  int ch = 0;
  ch = getFileByte(fd,fdTable[fd].offset);
  //kprintf("Fgetc: [%i][%i][%s]\n",fd,ch,fdTable[fd].fileName);
  fdTable[fd].offset++;
  return(ch);
  }