00001 /********************************************************************** 00002 00003 rubyio.h - 00004 00005 $Author: akr $ 00006 $Date: 2005/07/18 01:00:23 $ 00007 created at: Fri Nov 12 16:47:09 JST 1993 00008 00009 Copyright (C) 1993-2003 Yukihiro Matsumoto 00010 00011 **********************************************************************/ 00012 00013 #ifndef RUBYIO_H 00014 #define RUBYIO_H 00015 00016 #include <stdio.h> 00017 #include <errno.h> 00018 00019 #if defined(HAVE_STDIO_EXT_H) 00020 #include <stdio_ext.h> 00021 #endif 00022 00023 typedef struct OpenFile { 00024 FILE *f; /* stdio ptr for read/write */ 00025 FILE *f2; /* additional ptr for rw pipes */ 00026 int mode; /* mode flags */ 00027 int pid; /* child's pid (for pipes) */ 00028 int lineno; /* number of lines read */ 00029 char *path; /* pathname for file */ 00030 void (*finalize) (struct OpenFile*,int); /* finalize proc */ 00031 } OpenFile; 00032 00033 #define FMODE_READABLE 1 00034 #define FMODE_WRITABLE 2 00035 #define FMODE_READWRITE 3 00036 #define FMODE_APPEND 64 00037 #define FMODE_CREATE 128 00038 #define FMODE_BINMODE 4 00039 #define FMODE_SYNC 8 00040 #define FMODE_WBUF 16 00041 #define FMODE_RBUF 32 00042 #define FMODE_WSPLIT 0x200 00043 #define FMODE_WSPLIT_INITIALIZED 0x400 00044 00045 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) 00046 00047 #define MakeOpenFile(obj, fp) do {\ 00048 if (RFILE(obj)->fptr) {\ 00049 rb_io_close(obj);\ 00050 free(RFILE(obj)->fptr);\ 00051 RFILE(obj)->fptr = 0;\ 00052 }\ 00053 fp = 0;\ 00054 fp = RFILE(obj)->fptr = ALLOC(OpenFile);\ 00055 fp->f = fp->f2 = NULL;\ 00056 fp->mode = 0;\ 00057 fp->pid = 0;\ 00058 fp->lineno = 0;\ 00059 fp->path = NULL;\ 00060 fp->finalize = 0;\ 00061 } while (0) 00062 00063 #define GetReadFile(fptr) ((fptr)->f) 00064 #define GetWriteFile(fptr) (((fptr)->f2) ? (fptr)->f2 : (fptr)->f) 00065 00066 FILE *rb_fopen (const char*, const char*); 00067 FILE *rb_fdopen (int, const char*); 00068 int rb_getc (FILE*); 00069 long rb_io_fread (char *, long, FILE *); 00070 long rb_io_fwrite (const char *, long, FILE *); 00071 int rb_io_mode_flags (const char*); 00072 int rb_io_modenum_flags (int); 00073 void rb_io_check_writable (OpenFile*); 00074 void rb_io_check_readable (OpenFile*); 00075 void rb_io_fptr_finalize (OpenFile*); 00076 void rb_io_synchronized (OpenFile*); 00077 void rb_io_check_initialized (OpenFile*); 00078 void rb_io_check_closed (OpenFile*); 00079 int rb_io_wait_readable (int); 00080 int rb_io_wait_writable (int); 00081 00082 VALUE rb_io_taint_check (VALUE); 00084 void rb_eof_error (void); 00085 00086 void rb_read_check (FILE*); 00087 int rb_read_pending (FILE*); 00088 #endif 00089
1.3.5