mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 742179 - Move MakeRandomString to xpcom/ds. r=bsmedberg
This commit is contained in:
parent
802a8d64dd
commit
13bd86f4fd
@ -41,33 +41,7 @@
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
// XXX this code is ripped from profile/src/nsProfile.cpp and is further
|
||||
// duplicated in uriloader/exthandler. this should probably be moved
|
||||
// into xpcom or some other shared library.
|
||||
#include <stdlib.h>
|
||||
#define TABLE_SIZE 36
|
||||
static const char table[] =
|
||||
{ 'a','b','c','d','e','f','g','h','i','j',
|
||||
'k','l','m','n','o','p','q','r','s','t',
|
||||
'u','v','w','x','y','z','0','1','2','3',
|
||||
'4','5','6','7','8','9' };
|
||||
static void
|
||||
MakeRandomString(char *buf, PRInt32 bufLen)
|
||||
{
|
||||
// turn PR_Now() into milliseconds since epoch
|
||||
// and salt rand with that.
|
||||
double fpTime;
|
||||
LL_L2D(fpTime, PR_Now());
|
||||
srand((uint)(fpTime * 1e-6 + 0.5)); // use 1e-6, granularity of PR_Now() on the mac is seconds
|
||||
|
||||
PRInt32 i;
|
||||
for (i=0;i<bufLen;i++) {
|
||||
*buf++ = table[rand()%TABLE_SIZE];
|
||||
}
|
||||
*buf = 0;
|
||||
}
|
||||
// XXX
|
||||
#include "nsCRTGlue.h"
|
||||
|
||||
nsDownloader::~nsDownloader()
|
||||
{
|
||||
@ -116,7 +90,7 @@ nsDownloader::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char buf[13];
|
||||
MakeRandomString(buf, 8);
|
||||
NS_MakeRandomString(buf, 8);
|
||||
memcpy(buf+8, ".tmp", 5);
|
||||
rv = mLocation->AppendNative(nsDependentCString(buf, 12));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -69,33 +69,8 @@
|
||||
#include "nsITimer.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
// XXX Duped from profile/src/nsProfile.cpp.
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
#define TABLE_SIZE 36
|
||||
static const char table[] =
|
||||
{ 'a','b','c','d','e','f','g','h','i','j',
|
||||
'k','l','m','n','o','p','q','r','s','t',
|
||||
'u','v','w','x','y','z','0','1','2','3',
|
||||
'4','5','6','7','8','9' };
|
||||
static void
|
||||
MakeRandomString(char *buf, PRInt32 bufLen)
|
||||
{
|
||||
// turn PR_Now() into milliseconds since epoch
|
||||
// and salt rand with that.
|
||||
double fpTime;
|
||||
LL_L2D(fpTime, PR_Now());
|
||||
srand((uint)(fpTime * 1e-6 + 0.5)); // use 1e-6, granularity of PR_Now() on the mac is seconds
|
||||
|
||||
PRInt32 i;
|
||||
for (i=0;i<bufLen;i++) {
|
||||
*buf++ = table[rand()%TABLE_SIZE];
|
||||
}
|
||||
*buf = 0;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsDataObj::CStream, nsIStreamListener)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -1467,7 +1442,7 @@ HRESULT nsDataObj::DropImage(FORMATETC& aFE, STGMEDIUM& aSTG)
|
||||
// Photoshop which handle multiple drags into a single window.
|
||||
char buf[13];
|
||||
nsCString filename;
|
||||
MakeRandomString(buf, 8);
|
||||
NS_MakeRandomString(buf, 8);
|
||||
memcpy(buf+8, ".bmp", 5);
|
||||
filename.Append(nsDependentCString(buf, 12));
|
||||
dropFile->AppendNative(filename);
|
||||
|
@ -41,6 +41,9 @@
|
||||
#include "nsCRTGlue.h"
|
||||
#include "nsXPCOM.h"
|
||||
#include "nsDebug.h"
|
||||
#include "prtime.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
@ -270,6 +273,32 @@ bool NS_IsAsciiDigit(PRUnichar aChar)
|
||||
return aChar >= '0' && aChar <= '9';
|
||||
}
|
||||
|
||||
|
||||
#ifndef XPCOM_GLUE_AVOID_NSPR
|
||||
#define TABLE_SIZE 36
|
||||
static const char table[] = {
|
||||
'a','b','c','d','e','f','g','h','i','j',
|
||||
'k','l','m','n','o','p','q','r','s','t',
|
||||
'u','v','w','x','y','z','0','1','2','3',
|
||||
'4','5','6','7','8','9'
|
||||
};
|
||||
|
||||
void NS_MakeRandomString(char *aBuf, PRInt32 aBufLen)
|
||||
{
|
||||
// turn PR_Now() into milliseconds since epoch
|
||||
// and salt rand with that.
|
||||
double fpTime;
|
||||
LL_L2D(fpTime, PR_Now());
|
||||
srand((uint)(fpTime * 1e-6 + 0.5)); // use 1e-6, granularity of PR_Now() on the mac is seconds
|
||||
|
||||
PRInt32 i;
|
||||
for (i=0;i<aBufLen;i++) {
|
||||
*aBuf++ = table[rand()%TABLE_SIZE];
|
||||
}
|
||||
*aBuf = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(XP_WIN)
|
||||
void
|
||||
printf_stderr(const char *fmt, ...)
|
||||
|
@ -133,6 +133,10 @@ NS_COM_GLUE bool NS_IsAsciiWhitespace(PRUnichar aChar);
|
||||
NS_COM_GLUE bool NS_IsAscii(const char* aString);
|
||||
NS_COM_GLUE bool NS_IsAscii(const char* aString, PRUint32 aLength);
|
||||
|
||||
#ifndef XPCOM_GLUE_AVOID_NSPR
|
||||
NS_COM_GLUE void NS_MakeRandomString(char *buf, PRInt32 bufLen);
|
||||
#endif
|
||||
|
||||
#define FF '\f'
|
||||
#define TAB '\t'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user