Author Topic: open / read / close and others I/O functions  (Read 4457 times)

alekmaul (OP)

  • *
  • Posts: 330
    • Portabledev
open / read / close and others I/O functions
« on: October 26, 2009, 07:12:02 pm »
Hi all,
Just a little question for native OS dev.
I know that fopen / fread / fwrite can't be used and we need to call fsys_read / fsys_write, and so on.
I just want to know if someone already have try open / read / close native C functions ?
Same question about directory browsing (in dirent.h), does someone try these functions ?

Harteex

  • * Administrator
  • Posts: 709
    • Harteex Productions
Re: open / read / close and others I/O functions
« Reply #1 on: October 26, 2009, 07:51:12 pm »
if you want to use the names fopen etc you can just do a #define fopen(x, y) fsys_fopen(x, y) or is there any specific reason?

Although I did notice some problems with opening files with special characters, such as ?. So right now I'm looking into fsys_fopenW.

alekmaul (OP)

  • *
  • Posts: 330
    • Portabledev
Re: open / read / close and others I/O functions
« Reply #2 on: October 27, 2009, 07:45:28 am »
yes, i agree, but i talked about open / read / write (not fopen , and so on) to read/write streams in files.
I think i will also add function to mimic them ...
Like printf too, it's really difficult to debug something without printf ...

Spiller

  • *
  • Posts: 106
Re: open / read / close and others I/O functions
« Reply #3 on: October 29, 2009, 07:20:51 pm »
This is the stdio.h I'm using in dingkit:

Code: [Select]
#ifndef __stdio_h__
#define __stdio_h__

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>
#include <string.h>
#include <dingkit/fsys.h>

/* Map FILE on FSYS_FILE */
typedef FSYS_FILE FILE;

/* Standard streams.  */
#define stdin   NULL
#define stdout  NULL
#define stderr  NULL

/* EOF */
#ifndef EOF
#define EOF     -1
#endif

typedef long int fpos_t;

/* Import some functions from the system */
/* Note: fprintf should be replaced by a custom implementation! */
extern int    fprintf(FILE*, const char*, ...);
extern int    printf(const char*, ...);
extern int    sprintf(char*, const char*, ...);

//extern size_t fread(void*, size_t, size_t, FILE*);
//extern size_t fwrite(const void*, size_t, size_t, FILE*);
//extern int    fseek(FILE*, long int, int);

/* Map standard IO on fsys_* functions */
#define fopen(filename,mode)            fsys_fopen(filename,mode)
#define fclose(stream)                  fsys_fclose(stream)
#define fread(ptr,size,count,stream)    fsys_fread(ptr,size,count,stream)
#define fwrite(ptr,size,count,stream)   fsys_fwrite(ptr,size,count,stream)
#define fseek(stream,offset,origin)     fsys_fseek(stream,offset,origin)
#define rewind(stream)                  fsys_fseek(stream,0L,SEEK_SET);
#define ftell(stream)                   fsys_ftell(stream)
#define ferror(stream)                  fsys_ferror(stream)
#define feof(stream)                    fsys_feof(stream)
#define fputs(str,stream)               fsys_fwrite(str,1,strlen(str),stream)
#define remove(filename)                fsys_remove(filename)

/* Implement some functions which cannot be mapped */
extern int      fputc(int chr, FILE* stream);

#ifdef __cplusplus
}
#endif

#endif

Only thing missing is an implementation of fprintf. The system one does not work in conjuction with the fsys_* functions.

alekmaul (OP)

  • *
  • Posts: 330
    • Portabledev
Re: open / read / close and others I/O functions
« Reply #4 on: October 30, 2009, 12:30:10 pm »
Thanks a lot Spiller, that's help me a lot too but my need is read / write and open (http://www.opengroup.org/onlinepubs/000095399/functions/read.html)
Duke Nukem uses such function.
It's not very complicated to implement them, so i think i will do them

Spiller

  • *
  • Posts: 106
Re: open / read / close and others I/O functions
« Reply #5 on: October 30, 2009, 08:30:31 pm »
I guess those are not stdio functions, so... Ofcourse you can implement them yourself.

 

Post a new topic