From d596d043fc788e53adc6ceacd7ef37546179be00 Mon Sep 17 00:00:00 2001 From: Andrew McCallum Date: Sat, 15 Apr 1995 19:45:41 +0000 Subject: [PATCH] (-isWriteable): New method. (-initWithCoder): Renamed and rewritten from +newWithCoder. (-isAtEof): Renamed from -streamEof. (-initWithFilePointer:fmode:): Use new mode ivar. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@367 72102866-910b-0410-8b05-ffd578937521 --- Source/StdioStream.m | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Source/StdioStream.m b/Source/StdioStream.m index f39217b7e..b0c2b18a7 100644 --- a/Source/StdioStream.m +++ b/Source/StdioStream.m @@ -1,5 +1,5 @@ /* Implementation of GNU Objective C stdio stream - Copyright (C) 1994 Free Software Foundation, Inc. + Copyright (C) 1994, 1995 Free Software Foundation, Inc. Written by: R. Andrew McCallum Date: July 1994 @@ -26,6 +26,12 @@ #include #include +enum { + STREAM_READONLY = 0, + STREAM_READWRITE, + STREAM_WRITEONLY +}; + extern int objects_vscanf (void *stream, int (*inchar_func)(void*), @@ -63,25 +69,25 @@ objects_vscanf (void *stream, - initWithFilePointer: (FILE*)afp fmode: (const char *)mo { - int m; #if 0 /* xxx Is this portable? I don't think so. - How do I find out if a FILE* is open for reading/writing? */ + How do I find out if a FILE* is open for reading/writing? + I want to get rid of the "mode" instance variable. */ if (afp->_flag & _IOREAD) - m = STREAM_READONLY; + mode = STREAM_READONLY; else if (afp->_flag & _IOWRT) - m = STREAM_WRITEONLY; + mode = STREAM_WRITEONLY; else - m = STREAM_READWRITE; + mode = STREAM_READWRITE; #else if (!strcmp(mo, "rw")) - m = STREAM_READWRITE; + mode = STREAM_READWRITE; else if (*mo == 'r') - m = STREAM_READONLY; + mode = STREAM_READONLY; else if (*mo == 'w') - m = STREAM_WRITEONLY; + mode = STREAM_WRITEONLY; #endif - [super initWithMode:m]; + [super init]; fp = afp; return self; } @@ -192,7 +198,7 @@ stdio_unchar_func(void *s, int c) return ftell(fp); } -- (BOOL) streamEof +- (BOOL) isAtEof { if (feof(fp)) return YES; @@ -200,6 +206,14 @@ stdio_unchar_func(void *s, int c) return NO; } +- (BOOL) isWritable +{ + if (mode) + return YES; + else + return NO; +} + - (void) dealloc { fclose(fp); @@ -211,7 +225,7 @@ stdio_unchar_func(void *s, int c) [self notImplemented:_cmd]; } -+ newWithCoder: (Coder*)aDecoder +- initWithCoder: (Coder*)aDecoder { [self notImplemented:_cmd]; return self;