Subversion Repositories shark

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

/*
 *
 *
 *
 */


#include <kernel/func.h>

#include <fs/bdevinit.h>
#include <fs/fsinit.h>
#include <fs/bdev.h>

#include <drivers/keyb.h>

#include <sys/mount.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include "common.h"

#define FILENAME "/TEMP/TESTW1.TXT"

int scrivi(int h,char *buffer,int len)
{
  int res;
  cprintf("WRITING...\n");
  res=write(h,buffer,len);
  cprintf("WRITTEN %i bytes\n",res);
  if (res>0) {
    buffer[res]='\0';
    cprintf("(%s)\n",buffer);
  } else cprintf("errno: %i '%s'\n",errno,strerror(errno));
  return res;
}

extern dev_t temp_device;

int main(int argc,char *argv[])
{
  int res;
  int h;
 
  showmessage("Try to create and overwriting a file.\n");
 
  cprintf("OPENING %s\n",FILENAME);  
  h=open(FILENAME,O_CREAT|O_WRONLY|O_TRUNC);
 
  if (h>=0) {
    cprintf("OPENED fd=%i!\n",h);

    scrivi(h,"ABC ",3);
   
    scrivi(h,"abcdefghilmnopqrstuvz ",21);

    res=close(h);
    if (res!=0) {
      cprintf("CLOSE FAILED!\n");
      cprintf("errno: %i '%s'\n",errno,strerror(errno));
    }
  } else {
    cprintf("FAILED!\n");
    cprintf("errno: %i '%s'\n",errno,strerror(errno));
  }
 
  waitend();
 
  return 0;
}