This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fopen() w+ Fix


Hi All,

I've attached a proposed fix for fopen() with mode 'w+'. Basically specifying 'w+' was previously exactly the same as specifying 'r+', but 'w+' should allow file creation, while 'r+' should not.

I've split CYG_STREAM_READWRITE into CYG_STREAM_READWRITE_CREATE and CYG_STREAM_READWRITE_NOCREATE to allow for these different modes.

See here for details:
http://ecos.sourceware.org/ml/ecos-discuss/2004-03/msg00316.html

Thanks,
Kelvin.
diff -r -u5 -N -x CVS -x '*~' -x '.#*' clean/ecos/packages/language/c/libc/stdio/current/ChangeLog devo/ecos/packages/language/c/libc/stdio/current/ChangeLog
--- clean/ecos/packages/language/c/libc/stdio/current/ChangeLog	2003-09-03 16:37:55.000000000 +0100
+++ devo/ecos/packages/language/c/libc/stdio/current/ChangeLog	2004-03-29 10:48:33.812500000 +0100
@@ -1,5 +1,15 @@
+2004-03-29  Kelvin Lawson <klawson@ad-holdings.co.uk>
+
+	* src/common/fopen.cxx:
+	* src/common/stream.cxx:
+	* include/io.inl:
+	* include/stream.hxx:
+	Split CYGSTREAM_READWRITE into CYGSTREAM_READWRITE_CREATE and
+	CYGSTREAM_READWRITE_NOCREATE. This fixes fopen() with mode 'w+'
+	which previously did not allow file creation.
+
 2003-09-03  Thomas Koeller <thomas.koeller@baslerweb.com>
 
 	* cdl/stdio.cdl: only require "/dev/haldiag" if actually using it.
 
 2003-08-12  Scott Wilkinson <scott@alliantnetworks.com>
diff -r -u5 -N -x CVS -x '*~' -x '.#*' clean/ecos/packages/language/c/libc/stdio/current/include/io.inl devo/ecos/packages/language/c/libc/stdio/current/include/io.inl
--- clean/ecos/packages/language/c/libc/stdio/current/include/io.inl	2002-05-24 00:07:13.000000000 +0100
+++ devo/ecos/packages/language/c/libc/stdio/current/include/io.inl	2004-03-29 10:38:31.921875000 +0100
@@ -82,13 +82,16 @@
         mode = O_WRONLY|O_CREAT|O_TRUNC;
         break;
     case Cyg_StdioStream::CYG_STREAM_READ:
         mode = O_RDONLY;
         break;
-    case Cyg_StdioStream::CYG_STREAM_READWRITE:
+    case Cyg_StdioStream::CYG_STREAM_READWRITE_NOCREATE:
         mode = O_RDWR;
         break;
+    case Cyg_StdioStream::CYG_STREAM_READWRITE_CREATE:
+        mode = O_RDWR|O_CREAT|O_TRUNC;
+        break;
     }
 
     if( append )
     {
         mode |= O_APPEND;
diff -r -u5 -N -x CVS -x '*~' -x '.#*' clean/ecos/packages/language/c/libc/stdio/current/include/stream.hxx devo/ecos/packages/language/c/libc/stdio/current/include/stream.hxx
--- clean/ecos/packages/language/c/libc/stdio/current/include/stream.hxx	2002-05-24 00:07:14.000000000 +0100
+++ devo/ecos/packages/language/c/libc/stdio/current/include/stream.hxx	2004-03-29 10:39:01.843750000 +0100
@@ -155,23 +155,24 @@
 public:
     // different modes when constructing (i.e. opening).
     typedef enum {
         CYG_STREAM_READ,
         CYG_STREAM_WRITE,
-        CYG_STREAM_READWRITE
+        CYG_STREAM_READWRITE_NOCREATE,
+        CYG_STREAM_READWRITE_CREATE
     } OpenMode;
 
     // CONSTRUCTORS
 
     // This constructs the stream - effectively opens the file. This is
     // used for static initialisation, and actually calls construct below
     //
     // dev is a valid Cyg_Device_Table_t, although it does not have to
     // be a member of the device table object itself
     //
-    // open_mode is one of CYG_STREAM_READ, CYG_STREAM_WRITE or
-    // CYG_STREAM_READWRITE
+    // open_mode is one of CYG_STREAM_READ, CYG_STREAM_WRITE,
+    // CYG_STREAM_READWRITE_NOCREATE or CYG_STREAM_READWRITE_CREATE
     //
     // append is true if the file position should be set at EOF on opening
     //
     // binary is true if this is a binary stream. Otherwise it is a text
     // stream and character conversions (especially newline) may occur
diff -r -u5 -N -x CVS -x '*~' -x '.#*' clean/ecos/packages/language/c/libc/stdio/current/src/common/fopen.cxx devo/ecos/packages/language/c/libc/stdio/current/src/common/fopen.cxx
--- clean/ecos/packages/language/c/libc/stdio/current/src/common/fopen.cxx	2003-08-18 20:45:33.000000000 +0100
+++ devo/ecos/packages/language/c/libc/stdio/current/src/common/fopen.cxx	2004-03-29 10:37:52.796875000 +0100
@@ -110,22 +110,28 @@
     switch (mode[1]) {
     case 'b':
         *binary = true;
         break;
     case '+':
-        *rw = Cyg_StdioStream::CYG_STREAM_READWRITE;
+		if (mode[0] == 'r')
+	        *rw = Cyg_StdioStream::CYG_STREAM_READWRITE_NOCREATE;
+		else
+			*rw = Cyg_StdioStream::CYG_STREAM_READWRITE_CREATE;
         break;
     default:
         return false;
     } // switch
 
     switch (mode[2]) {
     case 'b':
         *binary = true;
         break;
     case '+':
-        *rw = Cyg_StdioStream::CYG_STREAM_READWRITE;
+		if (mode[0] == 'r')
+	        *rw = Cyg_StdioStream::CYG_STREAM_READWRITE_NOCREATE;
+		else
+			*rw = Cyg_StdioStream::CYG_STREAM_READWRITE_CREATE;
         break;
     default:
         return false;
     } // switch
     
diff -r -u5 -N -x CVS -x '*~' -x '.#*' clean/ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx devo/ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx
--- clean/ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx	2002-05-24 00:07:18.000000000 +0100
+++ devo/ecos/packages/language/c/libc/stdio/current/src/common/stream.cxx	2004-03-29 10:37:56.375000000 +0100
@@ -105,11 +105,12 @@
         flags.opened_for_read = true;
         break;
     case CYG_STREAM_WRITE:
         flags.opened_for_write = true;
         break;
-    case CYG_STREAM_READWRITE:
+    case CYG_STREAM_READWRITE_NOCREATE:
+    case CYG_STREAM_READWRITE_CREATE:
         flags.opened_for_read = true;
         flags.opened_for_write = true;
         break;
     default:
         error=EINVAL;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]