Changeset 1370
- Timestamp:
- Apr 15, 2004, 1:00:48 AM (21 years ago)
- Location:
- trunk/src/emx/src/lib
- Files:
-
- 1 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/emx/src/lib/app/stdio.c
-
Property cvs2svn:cvs-rev
changed from
1.8
to1.9
r1369 r1370 3 3 4 4 #include "libc-alias.h" 5 #include <stdio.h>6 #include <stdlib.h>7 5 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 8 6 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 9 7 #include <sys/rmutex.h> 8 #include <stdio.h> 9 #include <stdlib.h> 10 10 #include <emx/io.h> 11 11 #include <emx/startup.h> … … 22 22 23 23 /** Vector entry for preallocated streams. */ 24 static struct streamvec gPreStreamVec = {&gaPreFiles[0], NULL, _NFILES}; 25 26 /** More structures for preallocated streams. */ 27 static struct _file2 gaPreFile2s[_NFILES]; 24 static struct streamvec gPreStreamVec = {_NFILES, NULL, &gaPreFiles[0], NULL, _NFILES}; 28 25 29 26 /** The buffer for stdin. */ … … 38 35 */ 39 36 40 /** Head of the stream vector . */37 /** Head of the stream vector list. */ 41 38 struct streamvec *_streamvec_head = NULL; 39 /** Tail of the stream vector list. */ 40 struct streamvec *_streamvec_tail = NULL; 42 41 43 42 /** Standard input stream pointer. */ … … 58 57 LIBCLOG_ENTER("\n"); 59 58 struct _FILE *pFile; 60 struct _file2 *pFile2;61 59 int i; 62 60 static char fInited = 0; … … 74 72 */ 75 73 pFile = &gaPreFiles[0]; 76 pFile2 = &gaPreFile2s[0]; 77 for (i = 0; i < _NFILES; i++, pFile++, pFile2++) 78 { 79 pFile2->owner = pFile; /* obsolete? */ 80 pFile->_more = pFile2; 81 } 74 for (i = 0; i < _NFILES; i++, pFile++) 75 pFile->__pSV = &gPreStreamVec; 82 76 83 77 /* … … 85 79 * ASSUME: we're ALONE at this point. 86 80 */ 87 gPreStreamVec.next = _streamvec_head;88 81 _streamvec_head = &gPreStreamVec; 82 _streamvec_tail = &gPreStreamVec; 89 83 _rmutex_checked_create(&_streamv_rmutex, 0); 90 84 … … 102 96 * Common init - recall everything is ZERO. 103 97 */ 104 gaPreFiles[i]._flags |= _IOOPEN; 98 gPreStreamVec.cFree--; 99 gaPreFiles[i]._flags |= _IOOPEN | _IONOCLOSEALL; 105 100 gaPreFiles[i]._handle = i; 106 101 gaPreFiles[i]._flush = _flushstream; 107 if (_ setmore(&gaPreFiles[i], 0))102 if (_rmutex_create (&gaPreFiles[i].__u.__rsem, 0) != 0) 108 103 { 109 104 LIBC_ASSERTM_FAILED("_setmore failed for i=%d\n", i); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/_fopen.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <stdio.h>5 4 #include <io.h> 6 5 #include <fcntl.h> 7 6 #include <errno.h> 7 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 8 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 9 #include <sys/rmutex.h> 10 #include <stdio.h> 8 11 #include <emx/io.h> 9 12 … … 75 78 if (ok) ++mode; 76 79 } 77 dst->_ptr = NULL;78 dst->_buffer = NULL;79 dst->_buf_size = 0;80 dst->_rcount = 0;81 dst->_wcount = 0;82 dst->_tmpidx = 0;83 dst->_ungetc_count = 0;84 80 dst->_flags |= _IOOPEN | _IOBUFNONE; 85 81 dst->_flush = _flushstream; 86 if (_setmore (dst, lock) != 0) 87 return NULL; 82 if (_rmutex_create (&dst->__u.__rsem, 0) != 0) 83 { 84 _closestream (dst); 85 return NULL; 86 } 88 87 dst->_handle = sopen (fname, omode, shflag, 0644); 89 88 if (dst->_handle < 0) -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/_mfopen.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <stdio.h>5 4 #include <stdlib.h> 6 5 #include <errno.h> 6 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 7 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 8 #include <sys/rmutex.h> 9 #include <stdio.h> 7 10 #include <emx/io.h> 8 11 … … 86 89 stream->_tmpidx = inc; 87 90 stream->_ungetc_count = 0; 88 if (_ setmore (stream, 1) != 0)91 if (_rmutex_create (&stream->__u.__rsem, 0) != 0) 89 92 { 90 93 if (abuf != NULL) free (abuf); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/_newstre.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r1369 r1370 3 3 4 4 #include "libc-alias.h" 5 #include <stdio.h>6 5 #include <stdlib.h> 7 6 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 8 7 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 9 8 #include <sys/rmutex.h> 9 #include <stdio.h> 10 #include <emx/io.h> 10 11 #include <emx/umalloc.h> 11 #include <emx/io.h>12 12 13 #define INC 3213 #define INC 64 14 14 #define ALIGN(p, a) (((unsigned long)(p) + (a) - 1) & ~((a) - 1)) 15 15 … … 18 18 int i; 19 19 struct streamvec *pSV; 20 struct streamvec *pSVNew;21 20 22 21 /* 23 22 * Search thru the list of streams. 23 * Backwards as we're more likely to find free itmes at the end. 24 24 */ 25 25 STREAMV_LOCK; 26 for (pSV = _streamvec_ head; pSV != NULL; pSV = pSV->next)26 for (pSV = _streamvec_tail; pSV != NULL; pSV = pSV->pPrev) 27 27 { 28 for (i = 0; i < pSV->n; ++i)28 if (pSV->cFree > 0) 29 29 { 30 if (!(pSV->vec[i]._flags & (_IOOPEN|_IONEW)))30 for (i = 0; i < pSV->cFiles; ++i) 31 31 { 32 pSV->vec[i]._flags = _IONEW; 33 STREAMV_UNLOCK; 34 return &pSV->vec[i]; 32 if (!(pSV->aFiles[i]._flags & (_IOOPEN|_IONEW))) 33 { 34 pSV->aFiles[i]._flags = _IONEW; 35 pSV->cFree--; 36 STREAMV_UNLOCK; 37 38 /* 39 * We zero all members up till the __pSV member 40 * before returning the handle to the caller. 41 */ 42 memset(&pSV->aFiles[i], 0, offsetof(FILE, __pSV)); 43 return &pSV->aFiles[i]; 44 } 35 45 } 36 46 } … … 42 52 * (As the entries must not move, we add another segment.) 43 53 */ 44 pSV New= _hcalloc(1, sizeof(*pSV) + 1545 46 47 + INC * sizeof(struct _file2));48 if (pSV New)54 pSV = _hcalloc(1, sizeof(*pSV) + 15 55 + INC * sizeof(struct _FILE) 56 + 15 57 ); 58 if (pSV) 49 59 { 50 60 struct _FILE *pFile; 51 struct _file2 *pFile2;52 61 53 62 /* … … 55 64 * Remember everything is ZEROed by calloc()! 56 65 */ 57 pSVNew->vec = pFile = (struct _FILE *)ALIGN(pSVNew + 1, 16); 58 pFile2 = (struct _file2 *)ALIGN(&pFile[INC], 16); 59 pSVNew->vec = pFile; 60 pSVNew->n = INC; 61 for (i = 0; i < INC; i++, pFile++, pFile2++) 62 { 63 pFile2->owner = pFile; /* obsolete? */ 64 pFile->_more = pFile2; 65 } 66 pSV->aFiles = pFile = (struct _FILE *)ALIGN(pSV + 1, 16); 67 pSV->aFiles = pFile; 68 pSV->cFiles = INC; 69 pSV->cFree = INC - 1; 70 for (i = 0; i < INC; i++, pFile++) 71 pFile->__pSV = pSV; 66 72 67 73 /* 68 74 * Allocate the first one. 69 75 */ 70 pFile = &pSV New->vec[0];76 pFile = &pSV->aFiles[0]; 71 77 pFile->_flags = _IONEW; 72 78 … … 75 81 */ 76 82 STREAMV_LOCK; 77 if (_streamvec_head) 78 { 79 for (pSV = _streamvec_head; pSV; pSV = pSV->next) 80 if (!pSV->next) 81 { 82 pSV->next = pSVNew; 83 break; 84 } 85 } 83 pSV->pPrev = _streamvec_tail; 84 /* pNext is NULLed by calloc(). */ 85 if (_streamvec_tail) 86 _streamvec_tail = _streamvec_tail->pNext = pSV; 86 87 else 87 88 /* Someone fopen'ed something before streams were initated. */ 88 _streamvec_head = pSVNew;89 _streamvec_head = _streamvec_tail = pSV; 89 90 STREAMV_UNLOCK; 90 91 return pFile; … … 92 93 93 94 return NULL; 94 }95 96 /**97 * This used to set the _more member, but now it only create the mutex and98 * init _mbstate.99 *100 * @returns 0 on success.101 * @returns -1 on failure102 * @param stream Stream to init.103 * @param lock Ignored.104 */105 int _setmore(FILE *stream, int lock)106 {107 /*108 * Now this isn't so much work any longer, the streams are109 * allocated with a more buffer by default now.110 * All we gotta do is init _mbstate and create the mutex.111 */112 stream->_mbstate = 0;113 if (_rmutex_create(&stream->_more->rsem, 0) != 0)114 {115 /* free the stream */116 stream->_flags = 0;117 lock = lock;118 return -1;119 }120 return 0;121 }122 123 /**124 * This is used when creating a special stream for instance in vsprintf().125 *126 * @param stream Special stream.127 * @param more Dummy more block128 */129 void _setdummymore (FILE *stream, struct _file2 *more)130 {131 stream->_mbstate = 0;132 stream->_more = more;133 more->owner = stream;134 _rmutex_dummy(&more->rsem);135 95 } 136 96 … … 143 103 void _closestream(FILE *stream) 144 104 { 145 if ( stream->_more != NULL146 && stream->_more->owner == stream) /* paranoia */147 _rmutex_close(&stream->_more->rsem);148 105 stream->_flags = 0; 106 /* Assumption hare made about how the dummy stuff is made. */ 107 if (stream->__u.__rsem.fm.hev) 108 _rmutex_close(&stream->__u.__rsem); 109 110 if (stream->__pSV) 111 { 112 STREAMV_LOCK; 113 ((struct streamvec *)stream->__pSV)->cFree++; 114 STREAMV_UNLOCK; 115 } 149 116 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/_rmtmp.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r1369 r1370 17 17 18 18 n = 0; 19 for (sv = _streamvec_head; sv != NULL; sv = sv-> next)20 for (i = 0; i < sv-> n; ++i)21 if ((sv-> vec[i]._flags & _IOOPEN) && (sv->vec[i]._flags & _IOTMP)22 && STREAM_UNLOCKED (&sv-> vec[i])23 && fclose (&sv-> vec[i]) == 0)19 for (sv = _streamvec_head; sv != NULL; sv = sv->pNext) 20 for (i = 0; i < sv->cFiles; ++i) 21 if ((sv->aFiles[i]._flags & _IOOPEN) && (sv->aFiles[i]._flags & _IOTMP) 22 && STREAM_UNLOCKED (&sv->aFiles[i]) 23 && fclose (&sv->aFiles[i]) == 0) 24 24 ++n; 25 25 return n; -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/fcloseal.c
-
Property cvs2svn:cvs-rev
changed from
1.5
to1.6
r1369 r1370 12 12 13 13 n = 0; ok = 1; 14 for (sv = _streamvec_head; sv != NULL; sv = sv-> next)14 for (sv = _streamvec_head; sv != NULL; sv = sv->pNext) 15 15 { 16 for (i = sv->vec == stdin ? 3 : 0; /* Keep stdin, stdout, stderr */ 17 i < sv->n; 18 ++i) 19 if (sv->vec[i]._flags & _IOOPEN) 16 for (i = 0; i < sv->cFiles; ++i) 17 if ((sv->aFiles[i]._flags & (_IOOPEN | _IONOCLOSEALL)) == _IOOPEN) 20 18 { 21 if (fclose (&sv-> vec[i]) == 0)19 if (fclose (&sv->aFiles[i]) == 0) 22 20 ++n; 23 21 else -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/fdopen.c
-
Property cvs2svn:cvs-rev
changed from
1.5
to1.6
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <stdio.h>5 4 #include <io.h> 6 5 #include <fcntl.h> 7 6 #include <errno.h> 7 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 8 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 9 #include <sys/rmutex.h> 10 #include <stdio.h> 11 #include <stdio.h> 8 12 #include <emx/io.h> 9 13 … … 25 29 } 26 30 dst = _newstream (); 31 if (!dst) 32 return NULL; 33 if (_rmutex_create (&dst->__u.__rsem, 0) != 0) 34 { 35 _closestream (dst); 36 return NULL; 37 } 27 38 switch (*mode) 28 39 { … … 80 91 setmode (handle, omode); 81 92 dst->_handle = handle; 82 dst->_ptr = NULL;83 dst->_buffer = NULL;84 dst->_buf_size = 0;85 dst->_rcount = 0;86 dst->_wcount = 0;87 93 dst->_flags |= _IOOPEN | _IOBUFNONE; 88 94 dst->_flush = _flushstream; 89 dst->_ungetc_count = 0;90 if (_setmore (dst, 1) != 0)91 return NULL;92 95 return dst; 93 96 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/fflush.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r1369 r1370 73 73 if (stream == NULL) 74 74 { 75 for (sv = _streamvec_head; sv != NULL; sv = sv-> next)76 for (n = 0; n < sv-> n; ++n)77 if ((sv-> vec[n]._flags & (_IOOPEN|_IOWRT)) == (_IOOPEN|_IOWRT))78 if (fflush (&sv-> vec[n]) != 0)75 for (sv = _streamvec_head; sv != NULL; sv = sv->pNext) 76 for (n = 0; n < sv->cFiles; ++n) 77 if ((sv->aFiles[n]._flags & (_IOOPEN|_IOWRT)) == (_IOOPEN|_IOWRT)) 78 if (fflush (&sv->aFiles[n]) != 0) 79 79 result = EOF; 80 80 return result; -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/flushall.c
-
Property cvs2svn:cvs-rev
changed from
1.4
to1.5
r1369 r1370 18 18 19 19 n = 0; 20 for (sv = _streamvec_head; sv != NULL; sv = sv-> next)21 for (i = 0; i < sv-> n; ++i)22 if ((sv-> vec[i]._flags & _IOOPEN) && STREAM_LOCK_NOWAIT (&sv->vec[i]))20 for (sv = _streamvec_head; sv != NULL; sv = sv->pNext) 21 for (i = 0; i < sv->cFiles; ++i) 22 if ((sv->aFiles[i]._flags & _IOOPEN) && STREAM_LOCK_NOWAIT (&sv->aFiles[i])) 23 23 { 24 24 ++n; 25 _fflush_nolock (&sv-> vec[i]);26 STREAM_UNLOCK (&sv-> vec[i]);25 _fflush_nolock (&sv->aFiles[i]); 26 STREAM_UNLOCK (&sv->aFiles[i]); 27 27 } 28 28 return n; -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/snprintf.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 5 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 6 #include <sys/rmutex.h> 7 #include <stdio.h> 4 8 #include <stdio.h> 5 9 #include <stdarg.h> … … 11 15 va_list arg_ptr; 12 16 FILE trick; 13 struct _file2 trick2;14 17 int result; 15 18 … … 26 29 trick._flush = NULL; 27 30 trick._ungetc_count = 0; 28 _setdummymore (&trick, &trick2); 31 trick._mbstate = 0; 32 _rmutex_dummy(&trick.__u.__rsem); 29 33 result = _output (&trick, format, arg_ptr); 30 34 if (n != 0) -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/sprintf.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 5 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 6 #include <sys/rmutex.h> 7 #include <stdio.h> 4 8 #include <stdio.h> 5 9 #include <stdarg.h> … … 11 15 va_list arg_ptr; 12 16 FILE trick; 13 struct _file2 trick2;14 17 int result; 15 18 … … 24 27 trick._flush = NULL; 25 28 trick._ungetc_count = 0; 26 _setdummymore (&trick, &trick2); 29 trick._mbstate = 0; 30 _rmutex_dummy(&trick.__u.__rsem); 27 31 result = _output (&trick, format, arg_ptr); 28 32 putc (0, &trick); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/sscanf.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 5 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 6 #include <sys/rmutex.h> 7 #include <stdio.h> 4 8 #include <stdio.h> 5 9 #include <stdarg.h> … … 12 16 va_list arg_ptr; 13 17 FILE trick; 14 struct _file2 trick2;15 18 int result; 16 19 … … 25 28 trick._flush = NULL; 26 29 trick._ungetc_count = 0; 27 _setdummymore (&trick, &trick2); 30 trick._mbstate = 0; 31 _rmutex_dummy(&trick.__u.__rsem); 28 32 result = _input (&trick, format, arg_ptr); 29 33 va_end (arg_ptr); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/vsnprint.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 5 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 6 #include <sys/rmutex.h> 7 #include <stdio.h> 4 8 #include <stdio.h> 5 9 #include <limits.h> … … 9 13 { 10 14 FILE trick; 11 struct _file2 trick2;12 15 int result; 13 16 … … 23 26 trick._flush = NULL; 24 27 trick._ungetc_count = 0; 25 _setdummymore (&trick, &trick2); 28 trick._mbstate = 0; 29 _rmutex_dummy(&trick.__u.__rsem); 26 30 result = _output (&trick, format, arg_ptr); 27 31 if (n != 0) -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/vsprintf.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 5 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 6 #include <sys/rmutex.h> 7 #include <stdio.h> 4 8 #include <stdio.h> 5 9 #include <limits.h> … … 9 13 { 10 14 FILE trick; 11 struct _file2 trick2;12 15 int result; 13 16 … … 21 24 trick._flush = NULL; 22 25 trick._ungetc_count = 0; 23 _setdummymore (&trick, &trick2); 26 trick._mbstate = 0; 27 _rmutex_dummy(&trick.__u.__rsem); 24 28 result = _output (&trick, format, arg_ptr); 25 29 putc (0, &trick); -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/io/vsscanf.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r1369 r1370 2 2 3 3 #include "libc-alias.h" 4 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 5 #include <sys/fmutex.h> /* For <sys/rmutex.h> */ 6 #include <sys/rmutex.h> 7 #include <stdio.h> 4 8 #include <stdio.h> 5 9 #include <stdarg.h> … … 11 15 { 12 16 FILE trick; 13 struct _file2 trick2;14 17 int result; 15 18 … … 23 26 trick._flush = NULL; 24 27 trick._ungetc_count = 0; 25 _setdummymore (&trick, &trick2); 28 trick._mbstate = 0; 29 _rmutex_dummy(&trick.__u.__rsem); 26 30 result = _input (&trick, format, arg_ptr); 27 31 return result; -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.