xorg/tests: minor fixes

This commit is contained in:
Jay Sorg 2012-02-12 21:20:23 -08:00
parent 3e90b6c9cf
commit c37524c733

View File

@ -578,31 +578,38 @@ g_tcp_select(int sck1, int sck2)
return rv; return rv;
} }
/*****************************************************************************/ /*****************************************************************************/
void APP_CC void APP_CC
g_random(char* data, int len) g_random(char* data, int len)
{ {
#if defined(_WIN32) #if defined(_WIN32)
memset(data, 0x44, len); int index;
#else
int fd;
memset(data, 0x44, len); srand(g_time1());
fd = open("/dev/urandom", O_RDONLY); for (index = 0; index < len; index++)
if (fd == -1) {
data[index] = (char)rand(); /* rand returns a number between 0 and
RAND_MAX */
}
#else
int fd;
memset(data, 0x44, len);
fd = open("/dev/urandom", O_RDONLY);
if (fd == -1)
{
fd = open("/dev/random", O_RDONLY);
}
if (fd != -1)
{
if (read(fd, data, len) != len)
{ {
fd = open("/dev/random", O_RDONLY);
} }
if (fd != -1) close(fd);
{ }
read(fd, data, len); #endif
close(fd);
}
#endif
} }
/*****************************************************************************/ /*****************************************************************************/
int APP_CC int APP_CC
g_abs(int i) g_abs(int i)
@ -802,7 +809,6 @@ g_mkdir(const char* dirname)
#endif #endif
} }
/*****************************************************************************/ /*****************************************************************************/
/* gets the current working directory and puts up to maxlen chars in /* gets the current working directory and puts up to maxlen chars in
dirname dirname
@ -810,16 +816,17 @@ g_mkdir(const char* dirname)
char* APP_CC char* APP_CC
g_get_current_dir(char* dirname, int maxlen) g_get_current_dir(char* dirname, int maxlen)
{ {
#if defined(_WIN32) #if defined(_WIN32)
GetCurrentDirectory(maxlen, dirname); GetCurrentDirectoryA(maxlen, dirname);
return 0; return 0;
#else #else
getcwd(dirname, maxlen); if (getcwd(dirname, maxlen) == 0)
return 0; {
#endif }
return 0;
#endif
} }
/*****************************************************************************/ /*****************************************************************************/
/* returns error, zero on success and -1 on failure */ /* returns error, zero on success and -1 on failure */
int APP_CC int APP_CC