Skip to content

Commit 50fa508

Browse files
authored
Merge pull request #79 from sezero/libc1
reduce / fix platform-dependent code usage:
2 parents 4f549a3 + 7271329 commit 50fa508

File tree

7 files changed

+17
-31
lines changed

7 files changed

+17
-31
lines changed

src/libmodplug/stdafx.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
#define WIN32_LEAN_AND_MEAN
3636
#include <windows.h>
37-
#include <windowsx.h>
38-
#include <mmsystem.h>
37+
#include <mmsystem.h> /* for WAVE_FORMAT_PCM */
3938
#include <stdio.h>
4039
#include <malloc.h>
4140
#if defined(_MSC_VER) && (_MSC_VER < 1600)
@@ -49,9 +48,7 @@ typedef unsigned int uint32_t;
4948
#include <stdint.h>
5049
#endif
5150

52-
#define srandom(_seed) srand(_seed)
53-
#define random() rand()
54-
#define sleep(_ms) Sleep(_ms)
51+
#define sleep(_ms) Sleep(_ms * 1000)
5552

5653
inline void ProcessPlugins(int n) { (void)n; }
5754

@@ -91,7 +88,7 @@ typedef uint32_t* LPDWORD;
9188
typedef uint16_t WORD;
9289
typedef uint8_t BYTE;
9390
typedef uint8_t* LPBYTE;
94-
typedef bool BOOL;
91+
typedef bool BOOL; /* FIXME: must be 'int' */
9592
typedef char* LPSTR;
9693
typedef void* LPVOID;
9794
typedef uint16_t* LPWORD;
@@ -107,16 +104,6 @@ typedef void VOID;
107104

108105
#define WAVE_FORMAT_PCM 1
109106

110-
#define GHND 0
111-
#define GlobalFreePtr(p) free((void *)(p))
112-
inline int8_t * GlobalAllocPtr(unsigned int, size_t size)
113-
{
114-
int8_t * p = (int8_t *) malloc(size);
115-
116-
if (p != NULL) memset(p, 0, size);
117-
return p;
118-
}
119-
120107
inline void ProcessPlugins(int n) { (void)n; }
121108

122109
#ifndef FALSE

src/load_669.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
typedef struct tagFILEHEADER669
1818
{
1919
WORD sig; // 'if' or 'JN'
20-
signed char songmessage[108]; // Song Message
20+
char songmessage[108]; // Song Message
2121
BYTE samples; // number of samples (1-64)
2222
BYTE patterns; // number of patterns (1-128)
2323
BYTE restartpos;

src/load_abc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
#include <math.h>
3535
#include <ctype.h>
3636
#ifndef _WIN32
37-
#include <unistd.h> // for sleep
38-
#endif // _WIN32
37+
#include <unistd.h> /* sleep() */
38+
#endif
3939

4040
#include "stdafx.h"
4141
#include "sndfile.h"
@@ -2376,8 +2376,8 @@ static ABCHANDLE *ABC_Init(void)
23762376
}
23772377
}
23782378
else {
2379-
srandom((uint32_t)time(0)); // initialize random generator with seed
2380-
retval->pickrandom = 1+(int)(10000.0*random()/(RAND_MAX+1.0));
2379+
srand((unsigned int)time(0)); // initialize random generator with seed
2380+
retval->pickrandom = 1+(int)(10000.0*rand()/(RAND_MAX+1.0));
23812381
// can handle pickin' from songbooks with 10.000 songs
23822382
sprintf(buf,"%s=-%ld",ABC_ENV_NORANDOMPICK,retval->pickrandom); // xmms preloads the file
23832383
putenv(buf);

src/load_mid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <math.h>
3131
#include <ctype.h>
3232
#ifndef _WIN32
33-
#include <unistd.h> // for sleep
33+
#include <unistd.h> /* sleep() */
3434
#endif
3535

3636
#include "stdafx.h"

src/load_pat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
#endif
3737
#include <math.h>
3838
#include <ctype.h>
39-
#include <limits.h> // for PATH_MAX
39+
#include <limits.h> /* PATH_MAX */
4040
#ifndef _WIN32
41-
#include <unistd.h> // for sleep
41+
#include <unistd.h> /* sleep() */
4242
#endif
4343

4444
#include "stdafx.h"

src/mmcmp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ BOOL MMCMP_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength)
184184
return FALSE;
185185
}
186186
dwFileSize = pmmh->filesize;
187-
if ((pBuffer = (LPBYTE)GlobalAllocPtr(GHND, (dwFileSize + 31) & ~15)) == NULL)
187+
if ((pBuffer = (LPBYTE)calloc(1, (dwFileSize + 31) & ~15)) == NULL)
188188
return FALSE;
189189
pBufEnd = pBuffer + dwFileSize;
190190
pblk_table = (const DWORD *)(lpMemFile+pmmh->blktable);
@@ -538,7 +538,7 @@ BOOL PP20_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength)
538538
//Log("PP20 detected: Packed length=%d, Unpacked length=%d\n", dwMemLength, dwDstLen);
539539
if ((dwDstLen < 512) || (dwDstLen > 0x400000) || (dwDstLen > 16*dwMemLength))
540540
return FALSE;
541-
if ((pBuffer = (LPBYTE)GlobalAllocPtr(GHND, (dwDstLen + 31) & ~15)) == NULL)
541+
if ((pBuffer = (LPBYTE)calloc(1, (dwDstLen + 31) & ~15)) == NULL)
542542
return FALSE;
543543

544544
if (!ppDecrunch(lpMemFile+8, pBuffer, tmp, dwMemLength-12, dwDstLen, skip)) {

src/sndfile.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ BOOL CSoundFile::Create(LPCBYTE lpStream, DWORD dwMemLength)
167167
#ifdef MMCMP_SUPPORT
168168
if (bMMCmp)
169169
{
170-
GlobalFreePtr(lpStream);
170+
free((void*)lpStream);
171171
lpStream = NULL;
172172
}
173173
#endif
@@ -354,7 +354,7 @@ void CSoundFile::FreePattern(LPVOID pat)
354354
signed char* CSoundFile::AllocateSample(UINT nbytes)
355355
//-------------------------------------------
356356
{
357-
signed char * p = (signed char *)GlobalAllocPtr(GHND, (nbytes+39) & ~7);
357+
signed char * p = (signed char *)calloc(1, (nbytes+39) & ~7);
358358
if (p) p += 16;
359359
return p;
360360
}
@@ -363,9 +363,8 @@ signed char* CSoundFile::AllocateSample(UINT nbytes)
363363
void CSoundFile::FreeSample(LPVOID p)
364364
//-----------------------------------
365365
{
366-
if (p)
367-
{
368-
GlobalFreePtr(((LPSTR)p)-16);
366+
if (p) {
367+
free((char*)p - 16);
369368
}
370369
}
371370

0 commit comments

Comments
 (0)