DXGL r275 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r274‎ | r275 | r276 >
Date:20:35, 20 October 2012
Author:admin
Status:new
Tags:
Comment:
minilibc: Add _errno, _get_errno, and _set_errno
Modified paths:
  • /minilibc/errno.c (added) (history)
  • /minilibc/file.c (modified) (history)
  • /minilibc/minilibc.vcxproj (modified) (history)
  • /minilibc/minilibc.vcxproj.filters (modified) (history)

Diff [purge]

Index: minilibc/errno.c
@@ -0,0 +1,43 @@
 2+// DXGL
 3+// Copyright (C) 2012 William Feely
 4+
 5+// This library is free software; you can redistribute it and/or
 6+// modify it under the terms of the GNU Lesser General Public
 7+// License as published by the Free Software Foundation; either
 8+// version 2.1 of the License, or (at your option) any later version.
 9+
 10+// This library is distributed in the hope that it will be useful,
 11+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 12+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 13+// Lesser General Public License for more details.
 14+
 15+// You should have received a copy of the GNU Lesser General Public
 16+// License along with this library; if not, write to the Free Software
 17+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 18+
 19+#include "common.h"
 20+#include <errno.h>
 21+
 22+static int errorno;
 23+
 24+int *_errno()
 25+{
 26+ return &errorno;
 27+}
 28+
 29+errno_t _set_errno(int value)
 30+{
 31+ errorno = value;
 32+ return 0;
 33+}
 34+
 35+errno_t _get_errno(int *pValue)
 36+{
 37+ if(!pValue)
 38+ {
 39+ errorno = EINVAL;
 40+ return EINVAL;
 41+ }
 42+ *pValue = errorno;
 43+ return 0;
 44+}
\ No newline at end of file
Index: minilibc/file.c
@@ -125,7 +125,7 @@
126126 minilibc_files = (minilibc_FILE*)malloc(128*sizeof(minilibc_FILE));
127127 if(!minilibc_files)
128128 {
129 - errno = ENOMEM;
 129+ _set_errno(ENOMEM);
130130 return NULL;
131131 }
132132 memset(minilibc_files,0,128*sizeof(minilibc_FILE));
@@ -145,7 +145,7 @@
146146 minilibc_FILE *tmpptr = (minilibc_FILE*)realloc(minilibc_files,(128+maxfiles)*sizeof(minilibc_FILE));
147147 if(!tmpptr)
148148 {
149 - errno = ENOMEM;
 149+ _set_errno(ENOMEM);
150150 return NULL;
151151 }
152152 maxfiles += 128;
@@ -154,7 +154,7 @@
155155 minilibc_files[ptr].mode = decode_filemode(mode,&minilibc_files[ptr]);
156156 if(minilibc_files[ptr].mode & MODE_ERROR)
157157 {
158 - errno = EINVAL;
 158+ _set_errno(EINVAL);
159159 return NULL;
160160 }
161161 minilibc_files[ptr].handle = CreateFileA(filename,minilibc_files[ptr].DesiredAccess,
@@ -162,7 +162,7 @@
163163 FILE_ATTRIBUTE_NORMAL,NULL);
164164 if(minilibc_files[ptr].handle == INVALID_HANDLE_VALUE)
165165 {
166 - errno = EINVAL;
 166+ _set_errno(EINVAL);
167167 return NULL;
168168 }
169169 return (FILE*)&minilibc_files[ptr];
@@ -251,7 +251,7 @@
252252 minilibc_files = (minilibc_FILE*)malloc(128*sizeof(minilibc_FILE));
253253 if(!minilibc_files)
254254 {
255 - errno = ENOMEM;
 255+ _set_errno(ENOMEM);
256256 return NULL;
257257 }
258258 memset(minilibc_files,0,128*sizeof(minilibc_FILE));
@@ -271,7 +271,7 @@
272272 minilibc_FILE *tmpptr = (minilibc_FILE*)realloc(minilibc_files,(128+maxfiles)*sizeof(minilibc_FILE));
273273 if(!tmpptr)
274274 {
275 - errno = ENOMEM;
 275+ _set_errno(ENOMEM);
276276 return NULL;
277277 }
278278 maxfiles += 128;
@@ -280,7 +280,7 @@
281281 minilibc_files[ptr].mode = _w_decode_filemode(mode,&minilibc_files[ptr]);
282282 if(minilibc_files[ptr].mode & MODE_ERROR)
283283 {
284 - errno = EINVAL;
 284+ _set_errno(EINVAL);
285285 return NULL;
286286 }
287287 minilibc_files[ptr].handle = CreateFileW(filename,minilibc_files[ptr].DesiredAccess,
@@ -288,7 +288,7 @@
289289 FILE_ATTRIBUTE_NORMAL,NULL);
290290 if(minilibc_files[ptr].handle == INVALID_HANDLE_VALUE)
291291 {
292 - errno = EINVAL;
 292+ _set_errno(EINVAL);
293293 return NULL;
294294 }
295295 return (FILE*)&minilibc_files[ptr];
@@ -300,18 +300,18 @@
301301 minilibc_FILE *file;
302302 if(!stream)
303303 {
304 - errno = EINVAL;
 304+ _set_errno(EINVAL);
305305 return EOF;
306306 }
307307 file = (minilibc_FILE *)stream;
308308 if(file->handle == INVALID_HANDLE_VALUE)
309309 {
310 - errno = EINVAL;
 310+ _set_errno(EINVAL);
311311 return EOF;
312312 }
313313 if(!CloseHandle(file->handle))
314314 {
315 - errno = EINVAL;
 315+ _set_errno(EINVAL);
316316 return EOF;
317317 }
318318 return 0;
Index: minilibc/minilibc.vcxproj
@@ -105,6 +105,7 @@
106106 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
107107 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
108108 </ClCompile>
 109+ <ClCompile Include="errno.c" />
109110 <ClCompile Include="exit.c" />
110111 <ClCompile Include="file.c" />
111112 <ClCompile Include="init.c" />
Index: minilibc/minilibc.vcxproj.filters
@@ -50,6 +50,9 @@
5151 <ClCompile Include="file.c">
5252 <Filter>Source Files</Filter>
5353 </ClCompile>
 54+ <ClCompile Include="errno.c">
 55+ <Filter>Source Files</Filter>
 56+ </ClCompile>
5457 </ItemGroup>
5558 <ItemGroup>
5659 <ClInclude Include="common.h">