Skip to content

Commit 733fbf9

Browse files
committed
Allow query functions to return even when library is not initialized
Ignore multiple attempts to initialize library.
1 parent 35918dc commit 733fbf9

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

uspi/lib/uspilibrary.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static TUSPiLibrary *s_pLibrary = 0;
3333

3434
int USPiInitialize (void)
3535
{
36-
assert (s_pLibrary == 0);
36+
if (s_pLibrary != 0) return 1;
3737
s_pLibrary = (TUSPiLibrary *) malloc (sizeof (TUSPiLibrary));
3838
assert (s_pLibrary != 0);
3939

@@ -92,7 +92,7 @@ int USPiInitialize (void)
9292

9393
int USPiKeyboardAvailable (void)
9494
{
95-
assert (s_pLibrary != 0);
95+
if (s_pLibrary == 0) return 0;
9696
return s_pLibrary->pUKBD1 != 0;
9797
}
9898

@@ -119,7 +119,7 @@ void USPiKeyboardRegisterKeyStatusHandlerRaw (TKeyStatusHandlerRaw *pKeyStatusHa
119119

120120
int USPiMouseAvailable (void)
121121
{
122-
assert (s_pLibrary != 0);
122+
if (s_pLibrary == 0) return 0;
123123
return s_pLibrary->pUMouse1 != 0;
124124
}
125125

@@ -132,7 +132,7 @@ void USPiMouseRegisterStatusHandler (TUSPiMouseStatusHandler *pStatusHandler)
132132

133133
int USPiMassStorageDeviceAvailable (void)
134134
{
135-
assert (s_pLibrary != 0);
135+
if (s_pLibrary == 0) return 0;
136136

137137
unsigned i;
138138
for (i = 0; i < MAX_DEVICES; i++)
@@ -197,7 +197,7 @@ unsigned USPiMassStorageDeviceGetCapacity (unsigned nDeviceIndex)
197197

198198
int USPiEthernetAvailable (void)
199199
{
200-
assert (s_pLibrary != 0);
200+
if (s_pLibrary == 0) return 0;
201201
return s_pLibrary->pEth0 != 0;
202202
}
203203

@@ -227,7 +227,7 @@ int USPiReceiveFrame (void *pBuffer, unsigned *pResultLength)
227227

228228
int USPiGamePadAvailable (void)
229229
{
230-
assert (s_pLibrary != 0);
230+
if (s_pLibrary == 0) return 0;
231231

232232
unsigned i;
233233
for (i = 0; i < MAX_DEVICES; i++)
@@ -272,7 +272,7 @@ const USPiGamePadState *USPiGamePadGetStatus (unsigned nDeviceIndex)
272272

273273
int USPiDeviceGetInformation (unsigned nClass, unsigned nDeviceIndex, TUSPiDeviceInformation *pInfo)
274274
{
275-
assert (s_pLibrary != 0);
275+
if (s_pLibrary == 0) return 0;
276276

277277
TUSBDevice *pUSBDevice = 0;
278278

0 commit comments

Comments
 (0)