| 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 @@ |
| 126 | 126 | minilibc_files = (minilibc_FILE*)malloc(128*sizeof(minilibc_FILE));
|
| 127 | 127 | if(!minilibc_files)
|
| 128 | 128 | {
|
| 129 | | - errno = ENOMEM;
|
| | 129 | + _set_errno(ENOMEM);
|
| 130 | 130 | return NULL;
|
| 131 | 131 | }
|
| 132 | 132 | memset(minilibc_files,0,128*sizeof(minilibc_FILE));
|
| — | — | @@ -145,7 +145,7 @@ |
| 146 | 146 | minilibc_FILE *tmpptr = (minilibc_FILE*)realloc(minilibc_files,(128+maxfiles)*sizeof(minilibc_FILE));
|
| 147 | 147 | if(!tmpptr)
|
| 148 | 148 | {
|
| 149 | | - errno = ENOMEM;
|
| | 149 | + _set_errno(ENOMEM);
|
| 150 | 150 | return NULL;
|
| 151 | 151 | }
|
| 152 | 152 | maxfiles += 128;
|
| — | — | @@ -154,7 +154,7 @@ |
| 155 | 155 | minilibc_files[ptr].mode = decode_filemode(mode,&minilibc_files[ptr]);
|
| 156 | 156 | if(minilibc_files[ptr].mode & MODE_ERROR)
|
| 157 | 157 | {
|
| 158 | | - errno = EINVAL;
|
| | 158 | + _set_errno(EINVAL);
|
| 159 | 159 | return NULL;
|
| 160 | 160 | }
|
| 161 | 161 | minilibc_files[ptr].handle = CreateFileA(filename,minilibc_files[ptr].DesiredAccess,
|
| — | — | @@ -162,7 +162,7 @@ |
| 163 | 163 | FILE_ATTRIBUTE_NORMAL,NULL);
|
| 164 | 164 | if(minilibc_files[ptr].handle == INVALID_HANDLE_VALUE)
|
| 165 | 165 | {
|
| 166 | | - errno = EINVAL;
|
| | 166 | + _set_errno(EINVAL);
|
| 167 | 167 | return NULL;
|
| 168 | 168 | }
|
| 169 | 169 | return (FILE*)&minilibc_files[ptr];
|
| — | — | @@ -251,7 +251,7 @@ |
| 252 | 252 | minilibc_files = (minilibc_FILE*)malloc(128*sizeof(minilibc_FILE));
|
| 253 | 253 | if(!minilibc_files)
|
| 254 | 254 | {
|
| 255 | | - errno = ENOMEM;
|
| | 255 | + _set_errno(ENOMEM);
|
| 256 | 256 | return NULL;
|
| 257 | 257 | }
|
| 258 | 258 | memset(minilibc_files,0,128*sizeof(minilibc_FILE));
|
| — | — | @@ -271,7 +271,7 @@ |
| 272 | 272 | minilibc_FILE *tmpptr = (minilibc_FILE*)realloc(minilibc_files,(128+maxfiles)*sizeof(minilibc_FILE));
|
| 273 | 273 | if(!tmpptr)
|
| 274 | 274 | {
|
| 275 | | - errno = ENOMEM;
|
| | 275 | + _set_errno(ENOMEM);
|
| 276 | 276 | return NULL;
|
| 277 | 277 | }
|
| 278 | 278 | maxfiles += 128;
|
| — | — | @@ -280,7 +280,7 @@ |
| 281 | 281 | minilibc_files[ptr].mode = _w_decode_filemode(mode,&minilibc_files[ptr]);
|
| 282 | 282 | if(minilibc_files[ptr].mode & MODE_ERROR)
|
| 283 | 283 | {
|
| 284 | | - errno = EINVAL;
|
| | 284 | + _set_errno(EINVAL);
|
| 285 | 285 | return NULL;
|
| 286 | 286 | }
|
| 287 | 287 | minilibc_files[ptr].handle = CreateFileW(filename,minilibc_files[ptr].DesiredAccess,
|
| — | — | @@ -288,7 +288,7 @@ |
| 289 | 289 | FILE_ATTRIBUTE_NORMAL,NULL);
|
| 290 | 290 | if(minilibc_files[ptr].handle == INVALID_HANDLE_VALUE)
|
| 291 | 291 | {
|
| 292 | | - errno = EINVAL;
|
| | 292 | + _set_errno(EINVAL);
|
| 293 | 293 | return NULL;
|
| 294 | 294 | }
|
| 295 | 295 | return (FILE*)&minilibc_files[ptr];
|
| — | — | @@ -300,18 +300,18 @@ |
| 301 | 301 | minilibc_FILE *file;
|
| 302 | 302 | if(!stream)
|
| 303 | 303 | {
|
| 304 | | - errno = EINVAL;
|
| | 304 | + _set_errno(EINVAL);
|
| 305 | 305 | return EOF;
|
| 306 | 306 | }
|
| 307 | 307 | file = (minilibc_FILE *)stream;
|
| 308 | 308 | if(file->handle == INVALID_HANDLE_VALUE)
|
| 309 | 309 | {
|
| 310 | | - errno = EINVAL;
|
| | 310 | + _set_errno(EINVAL);
|
| 311 | 311 | return EOF;
|
| 312 | 312 | }
|
| 313 | 313 | if(!CloseHandle(file->handle))
|
| 314 | 314 | {
|
| 315 | | - errno = EINVAL;
|
| | 315 | + _set_errno(EINVAL);
|
| 316 | 316 | return EOF;
|
| 317 | 317 | }
|
| 318 | 318 | return 0;
|
| Index: minilibc/minilibc.vcxproj |
| — | — | @@ -105,6 +105,7 @@ |
| 106 | 106 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
| 107 | 107 | <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
| 108 | 108 | </ClCompile>
|
| | 109 | + <ClCompile Include="errno.c" />
|
| 109 | 110 | <ClCompile Include="exit.c" />
|
| 110 | 111 | <ClCompile Include="file.c" />
|
| 111 | 112 | <ClCompile Include="init.c" />
|
| Index: minilibc/minilibc.vcxproj.filters |
| — | — | @@ -50,6 +50,9 @@ |
| 51 | 51 | <ClCompile Include="file.c">
|
| 52 | 52 | <Filter>Source Files</Filter>
|
| 53 | 53 | </ClCompile>
|
| | 54 | + <ClCompile Include="errno.c">
|
| | 55 | + <Filter>Source Files</Filter>
|
| | 56 | + </ClCompile>
|
| 54 | 57 | </ItemGroup>
|
| 55 | 58 | <ItemGroup>
|
| 56 | 59 | <ClInclude Include="common.h">
|