Changeset 2536 for branches/libc-0.6
- Timestamp:
- Feb 6, 2006, 6:22:10 AM (20 years ago)
- Location:
- branches/libc-0.6/src/emx
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/libc-0.6/src/emx/ChangeLog.LIBC
r2535 r2536 2 2 3 3 TODO: open replace on RAMFS fails with error 32! 4 5 2006-02-06: knut st. osmundsen <bird-gccos2-spam@anduin.net> 6 - libc: 7 o #48: Quick implementation of the freopen(NULL,,) operation 8 to make cat from coreutils happy. 4 9 5 10 2006-02-04: knut st. osmundsen <bird-gccos2-spam@anduin.net> -
branches/libc-0.6/src/emx/src/lib/io/freopen.c
r1604 r2536 6 6 #include <string.h> 7 7 #include <share.h> 8 #include <errno.h> 9 #include <sys/fcntl.h> 8 10 #include <sys/builtin.h> /* For <sys/fmutex.h> */ 9 11 #include <sys/fmutex.h> 10 12 #include <emx/io.h> 13 14 #define FALSE 0 15 #define TRUE 1 11 16 12 17 FILE *_STD(freopen) (const char *fname, const char *mode, FILE *stream) … … 15 20 16 21 STREAMV_LOCK; 17 if (stream->_flags & _IOOPEN) 18 { /* duplication of fclose(), but no _closestream lock. */ 19 int result; 20 char buf[L_tmpnam]; 22 if (!fname) 23 { 24 /* 25 * Change the stream mode. 26 */ 27 /** @todo freopen(NULL,,) isn't 100% right, but it'll do for now I hope */ 28 result = stream; 29 if (result->_flags & _IOOPEN) 30 { 31 char bt, ok; 32 int omode = 0; 21 33 22 result = EOF; 23 if ((stream->_flags & _IOOPEN) && !(stream->_flags & _IOSPECIAL)) 34 switch (*mode) 35 { 36 case 'r': 37 if (!(result->_flags & (_IORW | _IOREAD))) 38 { 39 result = NULL; 40 errno = EINVAL; 41 } 42 omode = O_RDONLY; 43 break; 44 case 'w': 45 if (!(result->_flags & (_IORW | _IOWRT))) 46 { 47 result = NULL; 48 errno = EINVAL; 49 } 50 omode = O_WRONLY; 51 break; 52 case 'a': 53 if (!(result->_flags & (_IORW | _IOWRT))) 54 { 55 result = NULL; 56 errno = EINVAL; 57 } 58 omode = O_WRONLY | O_APPEND; 59 break; 60 default: 61 errno = EINVAL; 62 result = NULL; 63 break; 64 } 65 ++mode; ok = TRUE; bt = FALSE; 66 while (result && *mode != 0 && ok) 67 { 68 switch (*mode) 69 { 70 case 't': 71 if (bt) 72 ok = FALSE; 73 else 74 { 75 bt = TRUE; 76 omode |= O_TEXT; 77 } 78 break; 79 case 'b': 80 if (bt) 81 ok = FALSE; 82 else 83 { 84 bt = TRUE; 85 omode |= O_BINARY; 86 } 87 break; 88 case '+': 89 if (!(result->_flags & _IORW)) 90 { 91 result = NULL; 92 errno = EINVAL; 93 } 94 omode &= ~(O_RDONLY|O_WRONLY); 95 omode |= O_RDWR; 96 break; 97 default: 98 ok = FALSE; 99 break; 100 } 101 if (ok) 102 mode++; 103 } 104 105 /* 106 * Was the mode ok And does this stream have a handle? 107 */ 108 if (result && !(result->_flags & _IOSPECIAL)) 109 { 110 /* flush it and set the new mode */ 111 fflush(result); 112 int oldmode = setmode(fileno(result), omode); 113 if ( oldmode == -1 114 || (omode & O_APPEND) != (oldmode & O_APPEND)) 115 result = NULL; 116 } 117 } 118 else 24 119 { 25 result = 0; 26 result = fflush (stream); 27 if (close (stream->_handle) < 0) 28 result = EOF; 29 if (result == 0 && (stream->_flags & _IOTMP)) 120 errno = EBADF; 121 result = NULL; 122 } 123 } 124 else 125 { 126 if (stream->_flags & _IOOPEN) 127 { /* duplication of fclose(), but no _closestream lock. */ 128 int result; 129 char buf[L_tmpnam]; 130 131 result = EOF; 132 if ((stream->_flags & _IOOPEN) && !(stream->_flags & _IOSPECIAL)) 30 133 { 31 _itoa (stream->_tmpidx, buf, 10);32 strcat (buf, ".tmp");33 if ( remove (buf) !=0)134 result = 0; 135 result = fflush (stream); 136 if (close (stream->_handle) < 0) 34 137 result = EOF; 138 if (result == 0 && (stream->_flags & _IOTMP)) 139 { 140 _itoa (stream->_tmpidx, buf, 10); 141 strcat (buf, ".tmp"); 142 if (remove (buf) != 0) 143 result = EOF; 144 } 145 if ((stream->_flags & _IOBUFMASK) == _IOBUFLIB) 146 free (stream->_buffer); 35 147 } 36 if ((stream->_flags & _IOBUFMASK) == _IOBUFLIB) 37 free (stream->_buffer); 148 _closestream (stream); 38 149 } 39 _closestream (stream);150 result = _openstream (stream, fname, mode, SH_DENYNO, 0); 40 151 } 41 result = _openstream (stream, fname, mode, SH_DENYNO, 0);42 152 STREAMV_UNLOCK; 43 153 return result;
Note:
See TracChangeset
for help on using the changeset viewer.