Exemplo n.º 1
0
static BOOL
EnumSystemFiles(void (*func)(const char *))
{
    APIRET              rc;
    ULONG               sysInfo = 0;
    char                bootLetter[2];
    char                sysDir[_MAX_PATH] = "";
    char                filename[_MAX_PATH];
    HDIR                hdir = HDIR_CREATE;
    ULONG               numFiles = 1;
    FILEFINDBUF3        fileBuf = {0};
    ULONG               buflen = sizeof(FILEFINDBUF3);

    if (DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, (PVOID)&sysInfo,
                        sizeof(ULONG)) == NO_ERROR)
    {
      bootLetter[0] = sysInfo + 'A' -1;
      bootLetter[1] = '\0';
      strcpy(sysDir, bootLetter);
      strcpy(sysDir+1, ":\\OS2\\");

      strcpy( filename, sysDir );
      strcat( filename, "*.*" );
    }

    rc =DosFindFirst( filename, &hdir, FILE_NORMAL, &fileBuf, buflen,
                      &numFiles, FIL_STANDARD );
    if( rc == NO_ERROR )
    {
      do {
        // pass the full pathname to the callback
        sprintf( filename, "%s%s", sysDir, fileBuf.achName );
        (*func)(filename);

        numFiles = 1;
        rc = DosFindNext( hdir, &fileBuf, buflen, &numFiles );
        if( rc != NO_ERROR && rc != ERROR_NO_MORE_FILES )
          printf( "DosFindNext errod code = %d\n", rc );
      } while ( rc == NO_ERROR );

      rc = DosFindClose(hdir);
      if( rc != NO_ERROR )
        printf( "DosFindClose error code = %d", rc );
    }
    else
      printf( "DosFindFirst error code = %d", rc );

    return TRUE;
}
Exemplo n.º 2
0
ULONG QueryFreeMemory(void)
{
  APIRET rc;                                        /* operation return code */
  ULONG  ulFreeMemory = 0;

  rc = DosQuerySysInfo(QSV_TOTAVAILMEM,
                       QSV_TOTAVAILMEM,
                       &ulFreeMemory,
                       sizeof(ulFreeMemory) );
  if (rc != NO_ERROR)
    ToolsErrorDosEx(rc,
                    "QueryDosSystemInfo(QSV_TOTAVAILMEM)");

  return ulFreeMemory;
}
Exemplo n.º 3
0
DWORD VvGetAbsTimeMillisec (void)
{
     
    // here we need to read the OS/2 system clock and return the number
    // of ticks.  This is a 32-bit free running counter of the number
    // of milliseconds since power up.  Note that we will encounter
    // time wrap if PC is not powered down in 49.71 days
 
    DWORD milliseconds;
 
    if (DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &milliseconds, sizeof(ULONG)) != NO_ERROR )
       milliseconds = 0;

    return milliseconds;
}
Exemplo n.º 4
0
void xf86CloseConsole()
{
	APIRET rc;
	ULONG drive;

	if (xf86Info.consoleFd != -1) {
		KbdClose(xf86Info.consoleFd);
	}
	VioSetMode(&OriginalVideoMode,(HVIO)0);
	rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
	rc = DosSuppressPopUps(0x0000L,drive+96);    /* Reenable popups */
	rc = DosCloseEventSem(hevPopupPending);
	rc = VioDeRegister();
	return;
}
Exemplo n.º 5
0
FILE *pwfopen(const char *mode)
/*
 * Open the passwd file. In Unix, this file is always /etc/passwd. OS/2
 * installations have a variety of possible ETC directories. We try
 *
 *   1. x:\etc\passwd
 *   2. x:\mptn\etc\passwd
 *   3. x:\tcpip\etc\passwd
 *
 * where x: is the boot drive. If none of these can be opened, fail.
 */
{
	static	int	_pwfname_inited = 0;		/* initialised? */
	static	char	_pwfname_buf[CCHMAXPATH];	/* passwd file name */
		ULONG	ul;				/* buffer for DosQuerySysInfo() */
		FILE *	f;				/* return value */

	if (!_pwfname_inited) {

		/* determine boot drive */
		DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ul, sizeof(ul));

		/* try x:\etc\passwd */
		sprintf(_pwfname_buf, "%c:\\etc\\passwd", 'a' + ul - 1);
		if ((f = fopen(_pwfname_buf, mode))) {
			_pwfname_inited = 1;
			return (f);
		}

		/* try x:\mptn\etc\passwd */
		sprintf(_pwfname_buf, "%c:\\mptn\\etc\\passwd", 'a' + ul - 1);
		if ((f = fopen(_pwfname_buf, mode))) {
			_pwfname_inited = 1;
			return (f);
		}

		/* try x:\tcpip\etc\passwd */
		sprintf(_pwfname_buf, "%c:\\tcpip\\etc\\passwd", 'a' + ul - 1);
		if ((f = fopen(_pwfname_buf, mode))) {
			_pwfname_inited = 1;
			return (f);
		}

	} else {
		return (fopen(_pwfname_buf, mode));
	}
}
Exemplo n.º 6
0
static int32_t os2_mixer_event(uint32_t ulStatus, PMCI_MIX_BUFFER pBuffer,
                               uint32_t ulFlags)
{
  sa_stream_t * s;

  /* check for errors */
  if (ulFlags & MIX_STREAM_ERROR)
    os2_error(0, "os2_mixer_event", "MIX_STREAM_ERROR - status=", ulStatus);

  if (!(ulFlags & MIX_WRITE_COMPLETE))
    return os2_error(TRUE, "os2_mixer_event",
                     "unexpected event - flag=", ulFlags);

  if (!pBuffer || !pBuffer->ulUserParm)
    return os2_error(TRUE, "os2_mixer_event", "null pointer", 0);

  /* Note: this thread doesn't use a mutex to avoid a deadlock with the one
   * DART uses to prevent MCI operations while this function is running */
  s = (sa_stream_t *)pBuffer->ulUserParm;

  /* update the number of buffers that are now in use */
  s->usedCnt += __atomic_xchg(&s->usedNew, 0);
  s->usedCnt--;

  /* if fewer than 2 buffers are in use, enter recovery mode -
   * if we wait until they're all free, it's often too late; */
  if (s->usedCnt < s->usedMin) {
    s->playing = FALSE;
    os2_pause_device(s->hwDeviceID, FALSE);
    os2_error(0, "os2_mixer_event",
              "too few buffers in use - recovering", 0);
  }

  /* pass the number of newly played bytes to the other thread;
   * get the time so the other thread can estimate how many
   * additional bytes have been consumed since this event */
  __atomic_add(&s->writeNew, pBuffer->ulBufferLength);
  pBuffer->ulBufferLength = 0;
  DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT,
                  (void*)&s->writeTime, sizeof(s->writeTime));

  /* signal the decode thread that a buffer is available */
  __atomic_increment(&s->freeNew);

  return TRUE;
}
Exemplo n.º 7
0
// this definition needs to occur after __OS2MainInit() so that
// the #undef of _STACKLOW doesn't break things
void __OS2Init( int is_dll, thread_data *tdata )
/**********************************************/
{
    sys_info                    _sysinfo;

    __Is_DLL = is_dll;
    __FirstThreadData = tdata;

    DosQuerySysInfo( QSV_VERSION_MAJOR, QSV_VERSION_MINOR,
                     &_sysinfo, sizeof( sys_info )  );
    _RWD_osmajor = _sysinfo.version_major;
    _RWD_osminor = _sysinfo.version_minor;
    __saved_CS = GetCS();
#ifndef __SW_BM
#undef _STACKLOW
    _STACKLOW = (unsigned)&_end;            // cortns in F77
#endif
}
Exemplo n.º 8
0
/*
** PR_GetNumberOfProcessors()
** 
** Implementation notes:
**   Every platform does it a bit different.
**     numCpus is the returned value.
**   for each platform's "if defined" section
**     declare your local variable
**     do your thing, assign to numCpus
**   order of the if defined()s may be important,
**     especially for unix variants. Do platform
**     specific implementations before XP_UNIX.
** 
*/
PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
{
    PRInt32     numCpus;
#if defined(WIN32)
    SYSTEM_INFO     info;

    GetSystemInfo( &info );
    numCpus = info.dwNumberOfProcessors;
#elif defined(BEOS)
    system_info sysInfo;

    get_system_info(&sysInfo);
    numCpus = sysInfo.cpu_count;
#elif defined(OS2)
    DosQuerySysInfo( QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numCpus, sizeof(numCpus));
#elif defined(_PR_HAVE_SYSCTL)
    int mib[2];
    int rc;
    size_t len = sizeof(numCpus);

    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;
    rc = sysctl( mib, 2, &numCpus, &len, NULL, 0 );
    if ( -1 == rc )  {
        numCpus = -1; /* set to -1 for return value on error */
        _PR_MD_MAP_DEFAULT_ERROR( _MD_ERRNO() );
    }
#elif defined(HPUX)
    numCpus = mpctl( MPC_GETNUMSPUS, 0, 0 );
    if ( numCpus < 1 )  {
        numCpus = -1; /* set to -1 for return value on error */
        _PR_MD_MAP_DEFAULT_ERROR( _MD_ERRNO() );
    }
#elif defined(IRIX)
    numCpus = sysconf( _SC_NPROC_ONLN );
#elif defined(RISCOS) || defined(SYMBIAN)
    numCpus = 1;
#elif defined(XP_UNIX)
    numCpus = sysconf( _SC_NPROCESSORS_ONLN );
#else
#error "An implementation is required"
#endif
    return(numCpus);
} /* end PR_GetNumberOfProcessors() */
Exemplo n.º 9
0
unsigned long SysBootDrive(unsigned char *name,
                           unsigned long numargs,
                           RXSTRING args[],
                           char *queuename,
                           RXSTRING *retstr)
{
    unsigned long BootDrive[1];                  /* Major version number       */

#ifdef DLOGGING
    logmessage(__func__);
#endif

    if (numargs != 0) return INVALID_ROUTINE;

    DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, BootDrive, sizeof(BootDrive));

    retstr->strlength =  sprintf(retstr->strptr, "%c:", (char)(BootDrive[0]+64));

    return VALID_ROUTINE;
}
Exemplo n.º 10
0
Bool xf86VTSwitchTo()
{
	APIRET rc;
	ULONG drive,postCount;

	xf86Info.vtRequestsPending=FALSE;
	SwitchedToWPS=FALSE;
	rc = DosResetEventSem(hSwitchToSem,&postCount);
	DosPostEventSem(hevSwitchRequested);
	rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
	rc = DosSuppressPopUps(0x0001L,drive+96);     /* Disable popups */

	/* We reset the state of the control key */
	os2PostKbdEvent(KEY_LCtrl,1);
	os2PostKbdEvent(KEY_LCtrl,0);
	os2PostKbdEvent(KEY_RCtrl,1);
	os2PostKbdEvent(KEY_RCtrl,0);
	os2PostKbdEvent(KEY_Alt,1);
	os2PostKbdEvent(KEY_Alt,0);
	return(TRUE);
}
Exemplo n.º 11
0
// ticks() --
// -- returns the number of milliseconds elapsed since 
//    a system dependent date.
unsigned long 
GOS::ticks()
{
#if defined(UNIX)
  struct timeval tv;
  if (gettimeofday(&tv, NULL) < 0)
    G_THROW(errmsg());
  return (unsigned long)( ((tv.tv_sec & 0xfffff)*1000) 
                          + (tv.tv_usec/1000) );
#elif defined(WIN32)
  DWORD clk = GetTickCount();
  return (unsigned long)clk;
#elif defined(OS2)
  ULONG clk = 0;
  DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, (PVOID)&clk, sizeof(ULONG));
  return clk;
#elif defined(macintosh)
  return (unsigned long)((double)TickCount()*16.66);
#else
# error "Define something here for your operating system"
#endif
}
Exemplo n.º 12
0
/*--------------------------------------------------------------------------------------*\
 * UApm : intialize()                                                                   *
\*--------------------------------------------------------------------------------------*/
UApm                   &UApm::initialize(void)
{
    TIB    *ptib;                       /* Thread information block */
    PIB    *ppib;                       /* Process information block */
    char   *pcTemp;

                                        /* Query the fully qualified path APM/2 was loaded from.
                                           Once we know the language to use we replace ".exe"
                                           by e.g. "xx.msg" where xx is the NLS message file,
                                           but for now we assume English as this one is shipped
                                           with APM/2 for sure */
    DosGetInfoBlocks(&ptib, &ppib);
    DosQueryModuleName(ppib->pib_hmte, sizeof(acMessageFileUs), (PCHAR)acMessageFileUs);
    pcCommandline=strdup(strchr(ppib->pib_pchcmd, '\0')+1);
    pcTemp=strrchr(acMessageFileUs, '.');
    if(pcTemp!=0)
        strcpy(pcTemp, "Us.msg");
    strcpy(acMessageFileNls, acMessageFileUs);
                                        /* Query the version we're running */
    DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_VERSION_MINOR, ulVersion, sizeof(ulVersion));
    return(*this);
}
Exemplo n.º 13
0
int ReadMouseEvent(TEvent *Event, ULONG EventMask) {
  static unsigned short PrevState   = 0;
  static unsigned short PrevButtons = 0;
  static TEvent  LastMouseEvent     = { evNone };
  static ULONG   LastEventTime      = 0;
  static ULONG   LastClick          = 0;
  static ULONG   LastClickTime      = 0;
  static ULONG   LastClickCount     = 0;
  MOUEVENTINFO   mi;
  unsigned short Buttons, State, Btn;
  USHORT fWait = MOU_NOWAIT;
  MOUQUEINFO mq;
  ULONG CurTime;

  DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &CurTime, 4);

  Event->What = evNone;
  MouGetNumQueEl(&mq, MouseHandle);

  if (mq.cEvents == 0) {
    if ((LastMouseEvent.What == evMouseAuto) && (EventMask & evMouseAuto)) {
      if (TM_DIFF(CurTime, LastEventTime) >= MouseAutoRepeat) {
        *Event = LastMouseEvent;
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastEventTime, 4);
        return 1;
      }
    }

    if (((LastMouseEvent.What == evMouseDown) ||
         (LastMouseEvent.What == evMouseMove))
        &&
        (LastMouseEvent.Mouse.Buttons)
        && (EventMask & evMouseAuto)) {
      if (TM_DIFF(CurTime, LastEventTime) >= MouseAutoDelay) {
        LastMouseEvent.What = evMouseAuto;
        *Event              = LastMouseEvent;
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastEventTime, 4);
        return 1;
      }
    }
    return 0;
  }

  if (MouReadEventQue(&mi, &fWait, MouseHandle) != 0) return 0;

  Event->Mouse.X = mi.col;
  Event->Mouse.Y = mi.row;
  State          = mi.fs;
  Btn            = Buttons = ((State & (2 | 4)) ? 1 : 0) |
                             ((State & (8 | 16)) ? 2 : 0) |
                             ((State & (32 | 64)) ? 4 : 0);

  if (Buttons != PrevButtons) {
    Buttons ^= PrevButtons;

    if (PrevButtons & Buttons) Event->What = evMouseUp;
    else Event->What = evMouseDown;
  } else {
    Event->What = evMouseMove;

    if ((Event->Mouse.X == LastMouseEvent.Mouse.X) &&
        (Event->Mouse.Y == LastMouseEvent.Mouse.Y)) return 0;
  }
  Event->Mouse.Buttons = Buttons;
  Event->Mouse.Count   = 1;
  PrevState            = State;
  PrevButtons          = Btn;

  if (Event->What == evMouseDown) {
    if (LastClickCount) {
      if (LastClick == Event->Mouse.Buttons) {
        if (TM_DIFF(CurTime, LastClickTime) <= MouseMultiClick) {
          Event->Mouse.Count = ++LastClickCount;
        } else {
          LastClickCount = 0;
        }
      } else {
        LastClick      = 0;
        LastClickCount = 0;
        LastClickTime  = 0;
      }
    }

    LastClick = Event->Mouse.Buttons;

    if (LastClickCount == 0) LastClickCount = 1;
        DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastClickTime, 4);
  }

  /*    if (Event->What == evMouseMove) {
          LastClick = 0;
          LastClickCount = 0;
          LastClickTime = 0;
      }*/
  {
    KBDINFO  ki;
    USHORT   Flags;
    TKeyCode KeyFlags = 0;

    ki.cb = sizeof(ki);
    KbdGetStatus(&ki, 0);
    Flags = ki.fsState;

    if ((Flags & (LEFTSHIFT | RIGHTSHIFT)) != 0) KeyFlags |= kfShift;

    if ((Flags & (LEFTCONTROL | RIGHTCONTROL)) != 0) KeyFlags |= kfCtrl;

    if ((Flags & (LEFTALT | RIGHTALT)) != 0) KeyFlags |= kfAlt;

    Event->Mouse.KeyMask = KeyFlags;
  }

  LastMouseEvent = *Event;
  DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &LastEventTime, 4);
  return 1;
}
Exemplo n.º 14
0
PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(PRSysInfo cmd, char *buf, PRUint32 buflen)
{
    PRUintn len = 0;

    if (!_pr_initialized) _PR_ImplicitInitialization();

    switch(cmd)
    {
      case PR_SI_HOSTNAME:
      case PR_SI_HOSTNAME_UNTRUNCATED:
        if (PR_FAILURE == _PR_MD_GETHOSTNAME(buf, (PRUintn)buflen))
            return PR_FAILURE;

        if (cmd == PR_SI_HOSTNAME_UNTRUNCATED)
            break;
        /*
         * On some platforms a system does not have a hostname and
         * its IP address is returned instead.   The following code
         * should be skipped on those platforms.
         */
#ifndef _PR_GET_HOST_ADDR_AS_NAME
        /* Return the unqualified hostname */
            while (buf[len] && (len < buflen)) {
                if (buf[len] == '.') {
                    buf[len] = '\0';
                    break;
                }
                len += 1;
            }    
#endif
         break;

      case PR_SI_SYSNAME:
        /* Return the operating system name */
#if defined(XP_UNIX) || defined(WIN32)
        if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen))
            return PR_FAILURE;
#else
        (void)PR_snprintf(buf, buflen, _PR_SI_SYSNAME);
#endif
        break;

      case PR_SI_RELEASE:
        /* Return the version of the operating system */
#if defined(XP_UNIX) || defined(WIN32)
        if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen))
            return PR_FAILURE;
#endif
#if defined(XP_OS2)
        {
            ULONG os2ver[2] = {0};
            DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_REVISION,
                            &os2ver, sizeof(os2ver));
            /* Formatting for normal usage (2.11, 3.0, 4.0, 4.5); officially,
               Warp 4 is version 2.40.00, WSeB 2.45.00 */
            if (os2ver[0] < 30)
              (void)PR_snprintf(buf, buflen, "%s%lu",
                                "2.", os2ver[0]);
            else if (os2ver[0] < 45)
              (void)PR_snprintf(buf, buflen, "%lu%s%lu",
                                os2ver[0]/10, ".", os2ver[1]);
            else
              (void)PR_snprintf(buf, buflen, "%.1f",
                                os2ver[0]/10.0);
        }
#endif /* OS2 */
        break;

      case PR_SI_ARCHITECTURE:
        /* Return the architecture of the machine (ie. x86, mips, alpha, ...)*/
        (void)PR_snprintf(buf, buflen, _PR_SI_ARCHITECTURE);
        break;
	  default:
			PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
			return PR_FAILURE;
    }
    return PR_SUCCESS;
}
Exemplo n.º 15
0
/****************************************************************************
REMARKS:
Read the Long Period timer value from the BIOS timer tick.
****************************************************************************/
static ulong __ULZReadTime(void)
{
    ULONG   count;
    DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT, &count, sizeof(ULONG) );
    return count;
}
Exemplo n.º 16
0
APIRET TestMemory(void)
{
  APIRET rc = NO_ERROR;                                   /* API Return Code */
  ULONG  ulMemorySize;                 /* size of one memory object in bytes */
  ULONG  ulMemoryNumber;                         /* number of memory objects */
  ULONG  ulMemoryFlags;             /* allocation attributes for the objects */

  struct
  {
    ULONG ulPageSize;                                    /* system page size */
    ULONG ulTotalPhysicalMemory;                    /* total physical memory */
    ULONG ulTotalResidentMemory;                    /* total resident memory */
    ULONG ulTotalAvailableMemory;                  /* total available memory */
    ULONG ulMaximumPrivateMemory;        /* maximum available private memory */
    ULONG ulMaximumSharedMemory;          /* maximum available shared memory */
  } sSystemValues;


  /***************************************************************************
   * Query information about memory manager from the system                  *
   * calculating all necessary parameters and values                         *
   ***************************************************************************/

  rc = DosQuerySysInfo (QSV_PAGE_SIZE,
                        QSV_PAGE_SIZE,
                        &sSystemValues.ulPageSize,
                        sizeof(sSystemValues.ulPageSize));
  if (rc != NO_ERROR)
    return (rc);                                         /* abort with error */

  rc = DosQuerySysInfo (QSV_TOTPHYSMEM,
                        QSV_MAXSHMEM,
                        &sSystemValues.ulTotalPhysicalMemory,
                        5 * sizeof(sSystemValues.ulTotalPhysicalMemory)
                       );
  if (rc != NO_ERROR)
    return (rc);                                         /* abort with error */

#define PMEM(a) sSystemValues.a, \
  (float)sSystemValues.a / 1024.0, \
  (float)sSystemValues.a / 1024.0 / 1024.0

  printf ("\nMemory Information:"
          "\n  System page size        (PAGE) : %10ub   %10.3fk   %10.3fM"
          "\n  Total physical memory   (PHYS) : %10ub   %10.3fk   %10.3fM",
          PMEM(ulPageSize),
          PMEM(ulTotalPhysicalMemory));

  printf ("\n  Total resident memory          : %10ub   %10.3fk   %10.3fM"
          "\n  Total available memory (AVAIL) : %10ub   %10.3fk   %10.3fM",
          PMEM(ulTotalResidentMemory),
          PMEM(ulTotalAvailableMemory));

  printf ("\n  Available private memory (MAX) : %10ub   %10.3fk   %10.3fM"
          "\n  Available shared  memory (SHR) : %10ub   %10.3fk   %10.3fM",
          PMEM(ulMaximumPrivateMemory),
          PMEM(ulMaximumSharedMemory));
#undef PMEM

  if (Options.fsMemSize)
  {
    if (stricmp(Options.pszMemSize,
                "MAX") == 0)
      ulMemorySize = sSystemValues.ulMaximumPrivateMemory;
    else
    {
      if (stricmp(Options.pszMemSize,
                  "PHYS") == 0)
        ulMemorySize = sSystemValues.ulTotalPhysicalMemory;
      else
      {
        if (stricmp(Options.pszMemSize,
                    "AVAIL") == 0)
          ulMemorySize = sSystemValues.ulTotalAvailableMemory;
        else
        {
          if (stricmp(Options.pszMemSize,
                      "SHR") == 0)
            ulMemorySize = sSystemValues.ulMaximumSharedMemory;
          else
          {
            if (stricmp(Options.pszMemSize,
                        "PAGE") == 0)
              ulMemorySize = sSystemValues.ulPageSize;
            else
              ulMemorySize = atoi(Options.pszMemSize);
          }
        }
      }
    }
  }
  else
    ulMemorySize = 1024 * 1024;                            /* 1MB is default */

  if (Options.fsMemNumber)
    ulMemoryNumber = Options.ulMemNumber;
  else
    ulMemoryNumber = 1;                             /* one object is default */

  printf ("\n\nAllocating %u objects at size of %u bytes each, %u in total.",
          ulMemoryNumber,
          ulMemorySize,
          ulMemoryNumber * ulMemorySize);

  ulMemoryFlags = 0;
  printf ("\nMemory object attributes:");
#define MEMA(a,b) {ulMemoryFlags |= a; printf (b);}
  if (Options.fsMemCommit ) MEMA(PAG_COMMIT, " PAG_COMMIT");
  if (Options.fsMemWrite  ) MEMA(PAG_WRITE,  " PAG_WRITE");
  if (Options.fsMemRead   ) MEMA(PAG_READ,   " PAG_READ");
  if (Options.fsMemExecute) MEMA(PAG_EXECUTE," PAG_EXECUTE");
  if (Options.fsMemTile   ) MEMA(OBJ_TILE,   " OBJ_TILE");
#undef MEMA


  /***************************************************************************
   * Now allocating the memory.                                              *
   ***************************************************************************/


  /***************************************************************************
   * Now performing certain operations on that memory.                       *
   ***************************************************************************/


#if 0
  ARGFLAG fsOpQuery;          /* Perform query operations on the objects.    */
  ARGFLAG fsOpWrite;          /* Perform write operations on the objects.    */
  ARGFLAG fsOpRead;           /* Perform read  operations on the objects.    */
  ARGFLAG fsOpCheck;          /* Perform memory r/w tests on the objects.    */
  ARGFLAG fsOpForward;        /* Operation direction is forward.             */
  ARGFLAG fsOpBackward;       /* Operation direction is backward.            */
  ARGFLAG fsOpMixed;          /* Operation direction is mixed.               */
  ARGFLAG fsOpRandom;         /* Operation uses random addresses.            */
#endif


  return (NO_ERROR);                     /* return value to the main routine */
}
Exemplo n.º 17
0
ULONG ulExecProg (CHAR *szProgName)
   {
   ULONG        ulBootDrive;
   ULONG        ulAppType;
   CHAR         szCmdName[CCHMAXPATH];
   CHAR         szLine[CCHMAXPATH];
   PSZ          pszScanEnv;
   RESULTCODES  rcTermination;
   APIRET       rcFailure = 0;
   PCHAR        pszEnvironment;

/*
 *  Diese Routine versucht eine Shell zu starten.
 */

   pszEnvironment = MakeEnv (pShareInitOS2->pszEnvironment);

   if ( !(rcFailure = ScanEnv(ENV_SAMWORKPLACE, &pszScanEnv, pszEnvironment)) )
      {
      rcFailure = DosQueryAppType(pszScanEnv, &ulAppType);

      if ( !rcFailure )
         if ( ( (ulAppType & 7) == FAPPTYP_NOTSPEC) ||
              ( (ulAppType & 7) == FAPPTYP_WINDOWAPI) )
            rcFailure = DosExecPgm (szLine,           /* Object name buffer */
                                 sizeof(szLine),      /* Length of object name buffer */
                                 EXEC_ASYNCRESULT,    /* Execution flags */
                                 "",                  /* Argument string */
                                 pszEnvironment,       /* Environment */
                                 &rcTermination,      /* Termination codes */
                                 pszScanEnv);         /* Program file name */
         else
            rcFailure = 1;
      }

   if (rcFailure)
      {
      WinAlarm (HWND_DESKTOP, WA_ERROR);
      DebugS (1, "DosExecPgm <1> failed");
      }

   if (rcFailure)
      {
      rcFailure = DosExecPgm (szLine,              /* Object name buffer */
                              sizeof(szLine),      /* Length of object name buffer */
                              EXEC_ASYNCRESULT,    /* Execution flags */
                              "",                  /* Argument string */
                              pszEnvironment,       /* Environment */
                              &rcTermination,      /* Termination codes */
                              szProgName);         /* Program file name */
      }

   if (rcFailure)
      {
      if (!(rcFailure = DosScanEnv (ENV_SAMWORKPLACE, &pszScanEnv)))
         rcFailure = DosExecPgm (szLine,        /* Object name buffer */
                           sizeof(szLine),      /* Length of object name buffer */
                           EXEC_ASYNCRESULT,    /* Execution flags */
                           "",                  /* Argument string */
                           pszEnvironment,       /* Environment */
                           &rcTermination,      /* Termination codes */
                           pszScanEnv);         /* Program file name */
      }

   if (rcFailure)
      {
      DebugS (1, "DosExecPgm <2> failed");
      DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof (ULONG));

      memset (szCmdName, '\0', sizeof(szCmdName));
      szCmdName[0] = (CHAR) (ulBootDrive - 1) + 'A';
      strcpy (szCmdName+1, ":\\OS2\\PMSHELL.EXE");

      rcFailure = DosExecPgm (szLine,           /* Object name buffer */
                           sizeof(szLine),      /* Length of object name buffer */
                           EXEC_ASYNCRESULT,    /* Execution flags */
                           "",                  /* Argument string */
                           pszEnvironment,       /* Environment */
                           &rcTermination,      /* Termination codes */
                           szCmdName);          /* Program file name */
      }

/* Falls Shell nicht gestartet werden konnte, wird cmd.exe aufgerufen */

   if (rcFailure)
      {
      DebugS (1, "DosExecPgm <3> failed");
      if (!(rcFailure = DosScanEnv ("COMSPEC", &pszScanEnv)))
         rcFailure = DosExecPgm (szLine,        /* Object name buffer */
                           sizeof(szLine),      /* Length of object name buffer */
                           EXEC_ASYNCRESULT,    /* Execution flags */
                           "/K",                /* Argument string */
                           pszEnvironment,       /* Environment */
                           &rcTermination,      /* Termination codes */
                           pszScanEnv);         /* Program file name */
      }

   if (rcFailure)
      {
      DebugS (1, "DosExecPgm <4> failed");
      DosQuerySysInfo (QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulBootDrive, sizeof (ULONG));

      memset (szCmdName, '\0', sizeof(szCmdName));
      szCmdName[0] = (CHAR) (ulBootDrive - 1) + 'A';
      strcpy (szCmdName+1, ":\\OS2\\CMD.EXE");

      rcFailure = DosExecPgm (szLine,        /* Object name buffer */
                        sizeof(szLine),      /* Length of object name buffer */
                        EXEC_ASYNCRESULT,    /* Execution flags */
                        "/K",                /* Argument string */
                        pszEnvironment,       /* Environment */
                        &rcTermination,      /* Termination codes */
                        szCmdName);          /* Program file name */
      }

   DosFreeMem(pszEnvironment);

   if (rcFailure)
      {
      intSammyRetCode = rcFailure;
      WinPostQueueMsg (hmq, WM_CLOSE, 0L, 0L);
      DebugS (1, "DosExecPgm <5> failed");
      }

   return (rcFailure ? 0 : rcTermination.codeTerminate);
   }
nsresult
GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
                          nsIFile** aFile)
{
#if defined(XP_WIN)
    WCHAR path[MAX_PATH];
#else
    char path[MAXPATHLEN];
#endif

    switch (aSystemSystemDirectory)
    {
        case OS_CurrentWorkingDirectory:
#if defined(XP_WIN)
            if (!_wgetcwd(path, MAX_PATH))
                return NS_ERROR_FAILURE;
            return NS_NewLocalFile(nsDependentString(path),
                                   true,
                                   aFile);
#elif defined(XP_OS2)
            if (DosQueryPathInfo( ".", FIL_QUERYFULLNAME, path, MAXPATHLEN))
                return NS_ERROR_FAILURE;
#else
            if(!getcwd(path, MAXPATHLEN))
                return NS_ERROR_FAILURE;
#endif

#if !defined(XP_WIN)
            return NS_NewNativeLocalFile(nsDependentCString(path),
                                         true,
                                         aFile);
#endif

        case OS_DriveDirectory:
#if defined (XP_WIN)
        {
            PRInt32 len = ::GetWindowsDirectoryW(path, MAX_PATH);
            if (len == 0)
                break;
            if (path[1] == PRUnichar(':') && path[2] == PRUnichar('\\'))
                path[3] = 0;

            return NS_NewLocalFile(nsDependentString(path),
                                   true,
                                   aFile);
        }
#elif defined(XP_OS2)
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer),
                                         true,
                                         aFile);
        }
#else
        return NS_NewNativeLocalFile(nsDependentCString("/"),
                                     true,
                                     aFile);

#endif

        case OS_TemporaryDirectory:
#if defined (XP_WIN)
            {
            DWORD len = ::GetTempPathW(MAX_PATH, path);
            if (len == 0)
                break;
            return NS_NewLocalFile(nsDependentString(path, len),
                                   true,
                                   aFile);
        }
#elif defined(XP_OS2)
        {
            char *tPath = PR_GetEnv("TMP");
            if (!tPath || !*tPath) {
                tPath = PR_GetEnv("TEMP");
                if (!tPath || !*tPath) {
                    // if an OS/2 system has neither TMP nor TEMP defined
                    // then it is severely broken, so this will never happen.
                    return NS_ERROR_UNEXPECTED;
                }
            }
            nsCString tString = nsDependentCString(tPath);
            if (tString.Find("/", false, 0, -1)) {
                tString.ReplaceChar('/','\\');
            }
            return NS_NewNativeLocalFile(tString, true, aFile);
        }
#elif defined(MOZ_WIDGET_COCOA)
        {
            return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
        }

#elif defined(XP_UNIX)
        {
            static const char *tPath = nullptr;
            if (!tPath) {
                tPath = PR_GetEnv("TMPDIR");
                if (!tPath || !*tPath) {
                    tPath = PR_GetEnv("TMP");
                    if (!tPath || !*tPath) {
                        tPath = PR_GetEnv("TEMP");
                        if (!tPath || !*tPath) {
                            tPath = "/tmp/";
                        }
                    }
                }
            }
            return NS_NewNativeLocalFile(nsDependentCString(tPath),
                                         true,
                                         aFile);
        }
#else
        break;
#endif
#if defined (XP_WIN)
        case Win_SystemDirectory:
        {
            PRInt32 len = ::GetSystemDirectoryW(path, MAX_PATH);

            // Need enough space to add the trailing backslash
            if (!len || len > MAX_PATH - 2)
                break;
            path[len]   = L'\\';
            path[++len] = L'\0';

            return NS_NewLocalFile(nsDependentString(path, len),
                                   true,
                                   aFile);
        }

        case Win_WindowsDirectory:
        {
            PRInt32 len = ::GetWindowsDirectoryW(path, MAX_PATH);

            // Need enough space to add the trailing backslash
            if (!len || len > MAX_PATH - 2)
                break;

            path[len]   = L'\\';
            path[++len] = L'\0';

            return NS_NewLocalFile(nsDependentString(path, len),
                                   true,
                                   aFile);
        }

        case Win_ProgramFiles:
        {
            return GetWindowsFolder(CSIDL_PROGRAM_FILES, aFile);
        }

        case Win_HomeDirectory:
        {
            nsresult rv = GetWindowsFolder(CSIDL_PROFILE, aFile);
            if (NS_SUCCEEDED(rv))
                return rv;

            PRInt32 len;
            if ((len = ::GetEnvironmentVariableW(L"HOME", path, MAX_PATH)) > 0)
            {
                // Need enough space to add the trailing backslash
                if (len > MAX_PATH - 2)
                    break;

                path[len]   = L'\\';
                path[++len] = L'\0';

                rv = NS_NewLocalFile(nsDependentString(path, len),
                                     true,
                                     aFile);
                if (NS_SUCCEEDED(rv))
                    return rv;
            }

            len = ::GetEnvironmentVariableW(L"HOMEDRIVE", path, MAX_PATH);
            if (0 < len && len < MAX_PATH)
            {
                WCHAR temp[MAX_PATH];
                DWORD len2 = ::GetEnvironmentVariableW(L"HOMEPATH", temp, MAX_PATH);
                if (0 < len2 && len + len2 < MAX_PATH)
                    wcsncat(path, temp, len2);

                len = wcslen(path);

                // Need enough space to add the trailing backslash
                if (len > MAX_PATH - 2)
                    break;

                path[len]   = L'\\';
                path[++len] = L'\0';

                return NS_NewLocalFile(nsDependentString(path, len),
                                       true,
                                       aFile);
            }
        }
        case Win_Desktop:
        {
            return GetWindowsFolder(CSIDL_DESKTOP, aFile);
        }
        case Win_Programs:
        {
            return GetWindowsFolder(CSIDL_PROGRAMS, aFile);
        }

        case Win_Downloads:
        {
            // Defined in KnownFolders.h.
            GUID folderid_downloads = {0x374de290, 0x123f, 0x4565, {0x91, 0x64,
                                       0x39, 0xc4, 0x92, 0x5e, 0x46, 0x7b}};
            nsresult rv = GetKnownFolder(&folderid_downloads, aFile);
            // On WinXP, there is no downloads folder, default
            // to 'Desktop'.
            if(NS_ERROR_FAILURE == rv)
            {
              rv = GetWindowsFolder(CSIDL_DESKTOP, aFile);
            }
            return rv;
        }

        case Win_Controls:
        {
            return GetWindowsFolder(CSIDL_CONTROLS, aFile);
        }
        case Win_Printers:
        {
            return GetWindowsFolder(CSIDL_PRINTERS, aFile);
        }
        case Win_Personal:
        {
            return GetWindowsFolder(CSIDL_PERSONAL, aFile);
        }
        case Win_Favorites:
        {
            return GetWindowsFolder(CSIDL_FAVORITES, aFile);
        }
        case Win_Startup:
        {
            return GetWindowsFolder(CSIDL_STARTUP, aFile);
        }
        case Win_Recent:
        {
            return GetWindowsFolder(CSIDL_RECENT, aFile);
        }
        case Win_Sendto:
        {
            return GetWindowsFolder(CSIDL_SENDTO, aFile);
        }
        case Win_Bitbucket:
        {
            return GetWindowsFolder(CSIDL_BITBUCKET, aFile);
        }
        case Win_Startmenu:
        {
            return GetWindowsFolder(CSIDL_STARTMENU, aFile);
        }
        case Win_Desktopdirectory:
        {
            return GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, aFile);
        }
        case Win_Drives:
        {
            return GetWindowsFolder(CSIDL_DRIVES, aFile);
        }
        case Win_Network:
        {
            return GetWindowsFolder(CSIDL_NETWORK, aFile);
        }
        case Win_Nethood:
        {
            return GetWindowsFolder(CSIDL_NETHOOD, aFile);
        }
        case Win_Fonts:
        {
            return GetWindowsFolder(CSIDL_FONTS, aFile);
        }
        case Win_Templates:
        {
            return GetWindowsFolder(CSIDL_TEMPLATES, aFile);
        }
        case Win_Common_Startmenu:
        {
            return GetWindowsFolder(CSIDL_COMMON_STARTMENU, aFile);
        }
        case Win_Common_Programs:
        {
            return GetWindowsFolder(CSIDL_COMMON_PROGRAMS, aFile);
        }
        case Win_Common_Startup:
        {
            return GetWindowsFolder(CSIDL_COMMON_STARTUP, aFile);
        }
        case Win_Common_Desktopdirectory:
        {
            return GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, aFile);
        }
        case Win_Common_AppData:
        {
            return GetWindowsFolder(CSIDL_COMMON_APPDATA, aFile);
        }
        case Win_Printhood:
        {
            return GetWindowsFolder(CSIDL_PRINTHOOD, aFile);
        }
        case Win_Cookies:
        {
            return GetWindowsFolder(CSIDL_COOKIES, aFile);
        }
        case Win_Appdata:
        {
            nsresult rv = GetWindowsFolder(CSIDL_APPDATA, aFile);
            if (NS_FAILED(rv))
                rv = GetRegWindowsAppDataFolder(false, aFile);
            return rv;
        }
        case Win_LocalAppdata:
        {
            nsresult rv = GetWindowsFolder(CSIDL_LOCAL_APPDATA, aFile);
            if (NS_FAILED(rv))
                rv = GetRegWindowsAppDataFolder(true, aFile);
            return rv;
        }
#endif  // XP_WIN

#if defined(XP_UNIX)
        case Unix_LocalDirectory:
            return NS_NewNativeLocalFile(nsDependentCString("/usr/local/netscape/"),
                                         true,
                                         aFile);
        case Unix_LibDirectory:
            return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"),
                                         true,
                                         aFile);

        case Unix_HomeDirectory:
            return GetUnixHomeDir(aFile);

        case Unix_XDG_Desktop:
        case Unix_XDG_Documents:
        case Unix_XDG_Download:
        case Unix_XDG_Music:
        case Unix_XDG_Pictures:
        case Unix_XDG_PublicShare:
        case Unix_XDG_Templates:
        case Unix_XDG_Videos:
            return GetUnixXDGUserDirectory(aSystemSystemDirectory, aFile);
#endif

#ifdef XP_OS2
        case OS2_SystemDirectory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\System\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer),
                                         true,
                                         aFile);
        }

     case OS2_OS2Directory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer),
                                         true,
                                         aFile);
        }

     case OS2_HomeDirectory:
        {
            nsresult rv;
            char *tPath = PR_GetEnv("MOZILLA_HOME");
            char buffer[CCHMAXPATH];
            /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */
            /* To ensure we get a long filename system */
            if (!tPath || !*tPath) {
                PPIB ppib;
                PTIB ptib;
                DosGetInfoBlocks( &ptib, &ppib);
                DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
                *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
                tPath = buffer;
            }
            rv = NS_NewNativeLocalFile(nsDependentCString(tPath),
                                       true,
                                       aFile);

            PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", tPath);
            return rv;
        }

        case OS2_DesktopDirectory:
        {
            char szPath[CCHMAXPATH + 1];
            BOOL fSuccess;
            fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath));
            if (!fSuccess) {
                // this could happen if we are running without the WPS, return
                // the Home directory instead
                return GetSpecialSystemDirectory(OS2_HomeDirectory, aFile);
            }
            int len = strlen (szPath);
            if (len > CCHMAXPATH -1)
                break;
            szPath[len] = '\\';
            szPath[len + 1] = '\0';

            return NS_NewNativeLocalFile(nsDependentCString(szPath),
                                         true,
                                         aFile);
        }
#endif
        default:
            break;
    }
    return NS_ERROR_NOT_AVAILABLE;
}
Exemplo n.º 19
0
/*
** PR_GetPhysicalMemorySize()
** 
** Implementation notes:
**   Every platform does it a bit different.
**     bytes is the returned value.
**   for each platform's "if defined" section
**     declare your local variable
**     do your thing, assign to bytes.
** 
*/
PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
{
    PRUint64 bytes = 0;

#if defined(LINUX) || defined(SOLARIS)

    long pageSize = sysconf(_SC_PAGESIZE);
    long pageCount = sysconf(_SC_PHYS_PAGES);
    bytes = (PRUint64) pageSize * pageCount;

#elif defined(HPUX)

    struct pst_static info;
    int result = pstat_getstatic(&info, sizeof(info), 1, 0);
    if (result == 1)
        bytes = (PRUint64) info.physical_memory * info.page_size;

#elif defined(DARWIN)

    struct host_basic_info hInfo;
    mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;

    int result = host_info(mach_host_self(),
                           HOST_BASIC_INFO,
                           (host_info_t) &hInfo,
                           &count);
    if (result == KERN_SUCCESS)
        bytes = hInfo.max_mem;

#elif defined(WIN32)

    /* Try to use the newer GlobalMemoryStatusEx API for Windows 2000+. */
    GlobalMemoryStatusExFn globalMemory = (GlobalMemoryStatusExFn) NULL;
    HMODULE module = GetModuleHandleW(L"kernel32.dll");

    if (module) {
        globalMemory = (GlobalMemoryStatusExFn)GetProcAddress(module, "GlobalMemoryStatusEx");

        if (globalMemory) {
            PR_MEMORYSTATUSEX memStat;
            memStat.dwLength = sizeof(memStat);

            if (globalMemory(&memStat))
                bytes = memStat.ullTotalPhys;
        }
    }

    if (!bytes) {
        /* Fall back to the older API. */
        MEMORYSTATUS memStat;
        memset(&memStat, 0, sizeof(memStat));
        GlobalMemoryStatus(&memStat);
        bytes = memStat.dwTotalPhys;
    }

#elif defined(OS2)

    ULONG ulPhysMem;
    DosQuerySysInfo(QSV_TOTPHYSMEM,
                    QSV_TOTPHYSMEM,
                    &ulPhysMem,
                    sizeof(ulPhysMem));
    bytes = ulPhysMem;

#elif defined(AIX)

    if (odm_initialize() == 0) {
        int how_many;
        struct CuAt *obj = getattr("sys0", "realmem", 0, &how_many);
        if (obj != NULL) {
            bytes = (PRUint64) atoi(obj->value) * 1024;
            free(obj);
        }
        odm_terminate();
    }

#else

    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);

#endif

    return bytes;
} /* end PR_GetPhysicalMemorySize() */
Exemplo n.º 20
0
void *LAlloc( size_t size )
/*************************/
#endif
{
    void    *p;

    for( ;; ) {
#ifdef TRMEM
        p = _trmem_alloc( size, ra, TrHdl );

#elif defined( USE_OS2HMALLOC )

        /* Use all but 64MB of available low memory address space
           and then use available high memory.
           Os2_private_mem_left is a good enough estimate of
           address space remaining in the lower private arena.
           The goal is to leave a large chunk of address space available
           for the HLL_SECT_MISC section which is allocated at the end of pass1
           after most of the other memory allocations have been done
        */
        if( os2_private_mem_left > 64 * 1024 * 1024 &&
            size + 16 < os2_private_mem_left ) {
            p = malloc( size );
            if( p )
                os2_private_mem_left -= size + 16;
        }
        else {
            p = _os2hmalloc( size );
        }

#elif defined( OS2_MEM_HDR_MAGIC )
        /*
         * On OS/2 we will try use high memory when available. OS/2 has
         * two arenas for private memory, the Open Watcom heap is currently
         * only using the lower one. The lower arena is often smaller than
         * 128MB because of fragmentation caused by big applications (like
         * mozilla, openoffice, ..) in the shared arena above it. The high
         * arena on the other hand, is usually not subject to this kind of
         * fragmentation and will normally be able to provide more than
         * 400MB of contiguous virtual memory. Big links needs lots of
         * memory, so for medium/large allocations we try use the high memory.
         *
         * The allocations are identified by being at a fixed offset (16) into
         * a page and the header values (the 3 magics and the page aligned size).
         */
        static int fObjAny = -1;        /* -1 = check, 0 = no upper, 1 = have upper */
        static size_t minUpperAlloc = 0x2000;     /* 8 KBytes */
        if( fObjAny && size >= minUpperAlloc ) {
            APIRET rc;
            ULONG  ul;

            /*
             * Check if can allocate more than 512MB on the first call.
             * Will fail if upper arena does not exist.
             */
            if( fObjAny == -1) {
                rc = DosQuerySysInfo( QSV_VIRTUALADDRESSLIMIT,
                                      QSV_VIRTUALADDRESSLIMIT,
                                      &ul, sizeof( ul ) );
                fObjAny =   rc == NO_ERROR
                         && ul > 512 /*MB*/;
                if( !fObjAny )
                    continue; /* restart the loop */
            }

            /* Try allocate a block in the high arena. */
            ul = size + sizeof( os2_mem_hdr );  /* Make room for header */
            ul = ( ul + 0xfff ) & ~0xfffUL; /* Round up to 4K boundary */
            rc = DosAllocMem( &p, ul, OBJ_ANY | PAG_READ | PAG_WRITE | PAG_COMMIT );
            if(     rc == NO_ERROR
                &&  (uintptr_t)p >= 0x20000000UL /* 512MB */) {
               /* Mark allocation as coming from upper arena */
               os2_mem_hdr *hdr = (os2_mem_hdr *)p;
               hdr->magic = hdr->magic1 = hdr->magic2 = OS2_MEM_HDR_MAGIC;
               hdr->size = ul;
               p = hdr + 1;
               break;                   /* return pointer to caller */
            }
            if( rc == ERROR_INVALID_PARAMETER )
                fObjAny = FALSE;        /* Upper arena not supported */
            else if( rc == NO_ERROR )
                DosFreeMem( p );        /* Came for lower area - give back */
        }
        p = malloc( size );
        /* If lower arena allocation failed try upper arena unless time to die */
        if( p == NULL && fObjAny == TRUE && minUpperAlloc > 0x2000 ) {
            minUpperAlloc >>= 1;        /* Halve if more than 8192 */
            continue;                   /* Try again */
        }

#else /* ! OS2_MEM_HDR_MAGIC */
        p = malloc( size );
#endif
        if( p != NULL ) {
            memset( p, 0, size );
            break;
        }
        /* Try to free up some memory and try malloc */
        if( !FreeUpMemory() ) break;
    } /* for */
Exemplo n.º 21
0
static void __clock_init( void )
{
    DosQuerySysInfo( QSV_MS_COUNT, QSV_MS_COUNT,
                     &init_milliseconds, sizeof( init_milliseconds ) );
}
Exemplo n.º 22
0
void RNG_SystemInfoForRNG(void)
{
   unsigned long *plong = 0;
   PTIB ptib;
   PPIB ppib;
   APIRET rc = NO_ERROR;
   DATETIME dt;
   COUNTRYCODE cc = {0};
   COUNTRYINFO ci = {0};
   unsigned long actual = 0;
   char path[_MAX_PATH]="";
   char fullpath[_MAX_PATH]="";
   unsigned long pathlength = sizeof(path);
   FSALLOCATE fsallocate;
   FILESTATUS3 fstatus;
   unsigned long defaultdrive = 0;
   unsigned long logicaldrives = 0;
   unsigned long sysInfo[QSV_MAX] = {0};
   char buffer[20];
   int nBytes = 0;

   nBytes = RNG_GetNoise(buffer, sizeof(buffer));
   RNG_RandomUpdate(buffer, nBytes);
   
   /* allocate memory and use address and memory */
   plong = (unsigned long *)malloc(sizeof(*plong));
   RNG_RandomUpdate(&plong, sizeof(plong));
   RNG_RandomUpdate(plong, sizeof(*plong));
   free(plong);

   /* process info */
   rc = DosGetInfoBlocks(&ptib, &ppib);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(ptib, sizeof(*ptib));
      RNG_RandomUpdate(ppib, sizeof(*ppib));
   }

   /* time */
   rc = DosGetDateTime(&dt);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&dt, sizeof(dt));
   }

   /* country */
   rc = DosQueryCtryInfo(sizeof(ci), &cc, &ci, &actual);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&cc, sizeof(cc));
      RNG_RandomUpdate(&ci, sizeof(ci));
      RNG_RandomUpdate(&actual, sizeof(actual));
   }

   /* current directory */
   rc = DosQueryCurrentDir(0, path, &pathlength);
   strcat(fullpath, "\\");
   strcat(fullpath, path);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(fullpath, strlen(fullpath));
      // path info
      rc = DosQueryPathInfo(fullpath, FIL_STANDARD, &fstatus, sizeof(fstatus));
      if (rc == NO_ERROR)
      {
         RNG_RandomUpdate(&fstatus, sizeof(fstatus));
      }
   }

   /* file system info */
   rc = DosQueryFSInfo(0, FSIL_ALLOC, &fsallocate, sizeof(fsallocate));
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&fsallocate, sizeof(fsallocate));
   }

   /* drive info */
   rc = DosQueryCurrentDisk(&defaultdrive, &logicaldrives);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&defaultdrive, sizeof(defaultdrive));
      RNG_RandomUpdate(&logicaldrives, sizeof(logicaldrives));
   }

   /* system info */
   rc = DosQuerySysInfo(1L, QSV_MAX, (PVOID)&sysInfo, sizeof(ULONG)*QSV_MAX);
   if (rc == NO_ERROR)
   {
      RNG_RandomUpdate(&sysInfo, sizeof(sysInfo));
   }

   // now let's do some files
   ReadSystemFiles();

   /* more noise */
   nBytes = RNG_GetNoise(buffer, sizeof(buffer));
   RNG_RandomUpdate(buffer, nBytes);
}
Exemplo n.º 23
0
MRESULT EXPENTRY ProgressDlgProc(HWND hwnd,
                                 ULONG msg,
                                 MPARAM mp1,
                                 MPARAM mp2) {
   switch (msg) {
   // init -----------------------------------------------------------------
      case WM_INITDLG: {
         PPRGSAPPDATA pad = (PPRGSAPPDATA)mp2;
         ULONG ul;
         POINTL aptl[] = {{1, 36}, {220, 24}}; 
         WinSetWindowPtr(hwnd, 0L, (PVOID)mp2);
         WinSetWindowText(hwnd, pad->ppd->pszTitle);
         // dimensioni-coordinate varie
         pad->cyTitle = uGetSval(SV_CYTITLEBAR);
         pad->hButton = WinWindowFromID(hwnd, BTN_STOP);
         WinQueryWindowPos(pad->hButton, &pad->swp);
         WinQueryWindowRect(hwnd, &pad->rcl);
         WinMapDlgPoints(hwnd, aptl, 2, TRUE);
         pad->sldd.cbSize = sizeof(SLDCDATA);
         pad->sldd.usScale1Increments = 11;
         pad->sldd.usScale1Spacing = (pad->rcl.xRight - 2 * pad->cyTitle) / 10 - 1;
         pad->hProgress = WinCreateWindow(hwnd, WC_SLIDER, (PSZ)NULL,
                                          SLS_BOTTOM | SLS_OWNERDRAW |
                                          SLS_READONLY | SLS_RIBBONSTRIP |
                                          WS_VISIBLE, 3, aptl[0].y,
                                          pad->rcl.xRight - 6, aptl[1].y,
                                          hwnd, HWND_TOP, SLDR_PROGRESS,
                                          (PVOID)&pad->sldd, NULL);
         // controlla versione S.O. e setta font slider e bottone
         DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_MINOR,
                         &ul, sizeof(ULONG));
         if (ul < 40) {
            WinSetPresParam(pad->hProgress, PP_FONTNAMESIZE, 7, "8.Helv");
            WinSetPresParam(pad->hButton, PP_FONTNAMESIZE, 7, "8.Helv");
         } else {
            WinSetPresParam(pad->hProgress, PP_FONTNAMESIZE, 11, "9.WarpSans");
         } /* endif */
         // rileva larghezza progress bar
         pad->cxPrgs = LOUSHORT((ULONG)WinSendMsg(pad->hProgress,
                                                 SLM_QUERYSLIDERINFO,
                                         MPFROM2SHORT(SMA_SHAFTDIMENSIONS, 0),
                                         MPVOID)) - 6;
         // setta altezza barra pari a altezza barra titolo
         WinSendMsg(pad->hProgress, SLM_SETSLIDERINFO,
                    MPFROM2SHORT(SMA_SHAFTDIMENSIONS, 0), (MPARAM)pad->cyTitle);
         // setta testo e altezza barra graduata
         WinSendMsg(pad->hProgress, SLM_SETTICKSIZE,
                    MPFROM2SHORT(SMA_SETALLTICKS, pad->cyTitle / 3), MPVOID);
         WinSendMsg(pad->hProgress, SLM_SETSCALETEXT, (MPARAM)0, (MPARAM)"0%");
         WinSendMsg(pad->hProgress, SLM_SETSCALETEXT, (MPARAM)5, (MPARAM)"50%");
         WinSendMsg(pad->hProgress, SLM_SETSCALETEXT, (MPARAM)10, (MPARAM)"100%");
         // testo iniziale progesso e elapsed time:
         sprintf(pad->achElapsed, "%s: 00:00:00", pad->ppd->pszTime);
         WinSetDlgItemText(hwnd, TXT_TIME, pad->achElapsed);
         sprintf(pad->achCurPrg, "%s:   0%%", pad->ppd->pszPrgrss);
         WinSetDlgItemText(hwnd, TXT_PERCENT, pad->achCurPrg);
         // se specificato setta nuovo font dialogo
         if (pad->ppd->fl & PRGSS_FONT)
            WsetDlgFonts(hwnd, NULLHANDLE, pad->ppd->FontNameSize);
         // posiziona finestra al centro Parent window
         if (pad->ppd->fl & PRGSS_CENTER) {
            WcenterInWindow(hwnd, pad->ppd->hPos);
         } else {
            SWP swp;
            swp.hwnd = pad->ppd->hPos;
            swp.x = pad->ppd->ptl.x;
            swp.y = pad->ppd->ptl.y;
            swp.cx = swp.cy = 0;
            swp.fl = SWP_MOVE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER;
            swp.hwndInsertBehind = HWND_TOP;
            WsetRelativePos(hwnd, &swp);
         } // end if
         // notifica creazione dialogo
         WinPostMsg(pad->ppd->hNotify, WM_PRGRSREADY, (MPARAM)hwnd, (MPARAM)0);
         break;
      } // end case WM_INITDLG
      case WM_DRAWITEM:
         if (((POWNERITEM)mp2)->idItem == SDA_RIBBONSTRIP) {
            PPRGSAPPDATA pad = GetData(hwnd);
            if (pad->ppd->fl & PRGSS_BITMAP) {   // se deve disegnare la bitmap
               RECTL rcl = {0, 0, ((POWNERITEM)mp2)->rclItem.xRight -
                            ((POWNERITEM)mp2)->rclItem.xLeft, pad->cyTitle};
               POINTL ptl = {((POWNERITEM)mp2)->rclItem.xLeft,
                             ((POWNERITEM)mp2)->rclItem.yBottom};
               while (ptl.x < ((POWNERITEM)mp2)->rclItem.xRight) {
                  WinDrawBitmap(((POWNERITEM)mp2)->hps, pad->ppd->hbmp, &rcl,
                                &ptl, 0L, 0L, DBM_NORMAL);
                  ptl.x += pad->cxbmp;
                  rcl.xRight = ((POWNERITEM)mp2)->rclItem.xRight - ptl.x;
               } /* endwhile */
            } else {                       // colore
               GpiCreateLogColorTable(((POWNERITEM)mp2)->hps,
                                      0, LCOLF_RGB, 0, 0, NULL);
               WinFillRect(((POWNERITEM)mp2)->hps,
                           &((POWNERITEM)mp2)->rclItem, pad->ppd->color);
            } /* endif */
            return (MRESULT)TRUE;
         } // end if
         break;
      case PRGSM_INCREMENT: { // notifica incremento
         PPRGSAPPDATA pad = GetData(hwnd);
         ULONG ul;
         pad->incr = (ULONG)mp1;
         WinSendMsg(pad->hProgress,
                    SLM_SETSLIDERINFO,
                    MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE),
                    (MPARAM)((pad->incr * pad->cxPrgs) / 1000));
         ul = WinGetCurrentTime(pad->hab) / 1000;
         if (pad->current != ul) {
            pad->current = ul;
            pad->elapsed = pad->current - pad->start;
            sprintf(pad->achElapsed, "%s: %02d:%02d:%02d", pad->ppd->pszTime,
                    pad->elapsed / 3600, (pad->elapsed % 3600) / 60,
                    pad->elapsed % 60);
            WinSetDlgItemText(hwnd, TXT_TIME, pad->achElapsed);
         } // end if
         if (pad->ulCurPrg != (ul = (ULONG)mp1 / 10)) {
            pad->ulCurPrg = ul;
            sprintf(pad->achCurPrg, "%s: %3d %%",
                    pad->ppd->pszPrgrss, pad->ulCurPrg);
            WinSetDlgItemText(hwnd, TXT_PERCENT, pad->achCurPrg);
         } // end if
         return (MRESULT)pad->flStop;
      } // end case PRGSM_INCREMENT
      case PRGSM_MSG:
         return (MRESULT)Wprint(hwnd, (PSZ)mp1, (ULONG)mp2);
      case WM_COMMAND:
         if ((ULONG)mp1 == BTN_STOP) {
            PPRGSAPPDATA pad = GetData(hwnd);
            pad->flStop = TRUE;
            WinEnableWindow(pad->hButton, FALSE);
         } /* endif */
         break;
      case WM_CLOSE: {
         PPRGSAPPDATA pad = GetData(hwnd);
         // se elaborazione ancora in corso mostra messaggio
         if (pad->incr > 0 && pad->incr < 1000) {
            PSZ psz;
            if (!(psz = (PSZ)malloc(1024)) ||
            // se la notify window restituisce NULL
                (BOOL)WinSendMsg(pad->ppd->hNotify, WM_PRGRSQUIT,
                                 (MPARAM)psz, MPVOID) ||
            // o se la chiusura Š confermata
                Wprint(hwnd, psz, PMPRNT_QUERY)) {
               WinPostMsg(hwnd, PRGSM_END, MPVOID, MPVOID);
               WinPostMsg(pad->hOwner, WM_CLOSE, MPVOID, MPVOID);
            // se nel frattempo Š terminato
            } else {
               pad->qQuit.msg = 0;
               if (!pad->incr || pad->incr >= 1000) {
                  WinPostMsg(hwnd, PRGSM_END, MPVOID, MPVOID);
               } else if ((BOOL)mp1) {
                  WinCancelShutdown((HMQ)WinQueryWindowULong(hwnd, QWL_HMQ),
                                    FALSE);
               } // end if
            } // end if
            free (psz);
         } /* endif */
      }  break;
      default:
         return WinDefDlgProc(hwnd, msg, mp1, mp2);
   } /* endswitch */
   return (MRESULT)FALSE;
}
Exemplo n.º 24
0
char * hb_verPlatform( void )
{
   char * pszPlatform;

   HB_TRACE(HB_TR_DEBUG, ("hb_verPlatform()"));

   pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 );

#if defined(HB_OS_DOS)

   {
      union REGS regs;

      regs.h.ah = 0x30;
      HB_DOS_INT86( 0x21, &regs, &regs );

      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah );

      /* Host OS detection: Windows 2.x, 3.x, 95/98 */

      {
         regs.HB_XREGS.ax = 0x1600;
         HB_DOS_INT86( 0x2F, &regs, &regs );

         if( regs.h.al != 0x00 && regs.h.al != 0x80 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 0x01 || regs.h.al == 0xFF )
               hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }

      /* Host OS detection: Windows NT/2000 */

      {
         regs.HB_XREGS.ax = 0x3306;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.HB_XREGS.bx == 0x3205 )
            hb_strncat( pszPlatform, " (Windows NT/2000)", PLATFORM_BUF_SIZE );
      }

      /* Host OS detection: OS/2 */

      {
         regs.h.ah = 0x30;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.h.al >= 10 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 20 && regs.h.ah > 20 )
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }
   }

#elif defined(HB_OS_OS2)

   {
      unsigned long aulQSV[ QSV_MAX ] = { 0 };
      APIRET rc;

      rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX );

      if( rc == 0 )
      {
         /* is this OS/2 2.x ? */
         if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 )
         {
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld",
                      aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10,
                      aulQSV[ QSV_VERSION_MINOR - 1 ] );
         }
         else
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f",
                      ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 );
      }
      else
         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" );
   }

#elif defined(HB_OS_WIN_32)

   {
      OSVERSIONINFOA osVer;

      osVer.dwOSVersionInfoSize = sizeof( osVer );

      if( GetVersionExA( &osVer ) )
      {
         const char *szName = NULL;
         const char *szProduct = NULL;

         switch( osVer.dwPlatformId )
         {
            case VER_PLATFORM_WIN32_WINDOWS:

               if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion < 10 )
               {
                  szName = " 95";
               }
               else if( osVer.dwMajorVersion == 4 && osVer.dwMinorVersion == 10 )
               {
                  szName = " 98";
               }
               else
               {
                  szName = " ME";
               }

               break;

            case VER_PLATFORM_WIN32_NT:

               if( osVer.dwMajorVersion == 6 )
               {
                  szName = " Windows Vista";
               }
               else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion == 2 )
               {
                  szName = " Server 2003";
               }
               else if( osVer.dwMajorVersion == 5 && osVer.dwMinorVersion == 1 )
               {
                  szName = " XP";
               }
               else if( osVer.dwMajorVersion == 5 )
               {
                  szName = " 2000";
               }
               else
               {
                  szName = " NT";
               }

               /* test for specific product on Windows NT 4.0 SP6 and later */

               {
                  HBOSVERSIONINFOEX osVerEx;  /* NOTE */

                  osVerEx.dwOSVersionInfoSize = sizeof( osVerEx );

                                    /* Windows decl error? */
                  if( GetVersionEx( ( LPOSVERSIONINFOA ) &osVerEx ) )
                  {
                     /* workstation type */

                     if( osVerEx.wProductType == VER_NT_WORKSTATION )
                     {
                        if( osVerEx.dwMajorVersion == 4 )
                        {
                           szProduct =  " Workstation 4.0";
                        }
                        else if( osVerEx.wSuiteMask & VER_SUITE_PERSONAL )
                        {
                           szProduct = " Home Edition";
                        }
                        else
                        {
                           szProduct = " Professional";
                        }
                     }

                     /* server type */

                     else if( osVerEx.wProductType == VER_NT_SERVER )
                     {
                        if( osVerEx.dwMajorVersion == 5 && osVerEx.dwMinorVersion == 2 )
                        {
                           if( osVerEx.wSuiteMask & VER_SUITE_DATACENTER )
                           {
                              szProduct = " Datacenter Edition";
                           }
                           else if( osVerEx.wSuiteMask & VER_SUITE_ENTERPRISE )
                           {
                              szProduct = " Enterprise Edition";
                           }
                           else if( osVerEx.wSuiteMask == VER_SUITE_BLADE )
                           {
                              szProduct = " Web Edition";
                           }
                           else
                           {
                              szProduct = " Standard Edition";
                           }
                        }

                        else if( osVerEx.dwMajorVersion == 5 && osVerEx.dwMinorVersion == 0 )
                        {
                           if( osVerEx.wSuiteMask & VER_SUITE_DATACENTER )
                           {
                              szProduct = " Datacenter Server";
                           }
                           else if( osVerEx.wSuiteMask & VER_SUITE_ENTERPRISE )
                           {
                              szProduct = " Advanced Server";
                           }
                           else
                           {
                              szProduct = " Server";
                           }
                        }

                        else
                        {
                           if( osVerEx.wSuiteMask & VER_SUITE_ENTERPRISE )
                           {
                              szProduct = " Server 4.0, Enterprise Edition";
                           }
                           else
                           {
                              szProduct = " Server 4.0";
                           }
                        }
                     }
                  }
               }

               break;

            case VER_PLATFORM_WIN32s:
               szName = " 32s";
               break;

            case VER_PLATFORM_WIN32_CE:
               szName = " CE";
               break;
         }

         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows %s%s %lu.%02lu.%04d",
                   szName ? szName : NULL, szProduct ? szProduct : "",
                   ( ULONG ) osVer.dwMajorVersion,
                   ( ULONG ) osVer.dwMinorVersion,
                   ( USHORT ) LOWORD( osVer.dwBuildNumber ) );

         /* Add service pack/other info */

         if( osVer.szCSDVersion )
         {
            int i;

            /* Skip the leading spaces (Win95B, Win98) */
            for( i = 0; osVer.szCSDVersion[ i ] != '\0' && isspace( ( int ) osVer.szCSDVersion[ i ] ); i++ ) {};

            if( osVer.szCSDVersion[ i ] != '\0' )
            {
               hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE );
               hb_strncat( pszPlatform, osVer.szCSDVersion + i, PLATFORM_BUF_SIZE );
            }
         }
      }
      else
         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows" );
   }

#elif defined(__CEGCC__)
   {
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" );
   }
#elif defined(HB_OS_UNIX)

   {
      struct utsname un;

      uname( &un );
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine );
   }

#elif defined(HB_OS_MAC)

   {
      hb_strncpy( pszPlatform, "MacOS compatible", PLATFORM_BUF_SIZE );
   }

#else

   {
      hb_strncpy( pszPlatform, "(unknown)", PLATFORM_BUF_SIZE );
   }

#endif

   return pszPlatform;
}
Exemplo n.º 25
0
//----------------------------------------------------------------------------------------
void nsSpecialSystemDirectory::operator = (SystemDirectories aSystemSystemDirectory)
//----------------------------------------------------------------------------------------
{
    SystemDirectoriesKey dirKey(aSystemSystemDirectory);
    SystemDirectoriesKey mozBinDirKey(Moz_BinDirectory);

    // This flag is used to tell whether or not we need to append something
    // onto the *this.  Search for needToAppend to how it's used.
    // IT's VERY IMPORTANT that needToAppend is initialized to PR_TRUE.
    PRBool needToAppend = PR_TRUE;

    *this = (const char*)nsnull;
    switch (aSystemSystemDirectory)
    {
        
        case OS_DriveDirectory:
#if defined (XP_WIN)
        {
            char path[_MAX_PATH];
            PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
            if (len)
            {
                if ( path[1] == ':' && path[2] == '\\' )
                    path[3] = 0;
            }
            *this = MakeUpperCase(path);
        }
#elif defined(XP_OS2)
        {
            // printf( "*** Warning warning OS_DriveDirectory called for");
            
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
            *this = buffer;
#ifdef DEBUG
            printf( "Got OS_DriveDirectory: %s\n", buffer);
#endif
        }
#else
        *this = "/";
#endif
        break;

            
        case OS_TemporaryDirectory:
#if defined (WINCE)
            {
                *this = "\\TEMP";
            }
#elif defined (XP_WIN)
        {
            char path[_MAX_PATH];
            DWORD len = GetTempPath(_MAX_PATH, path);
            *this = MakeUpperCase(path);
        }
#elif defined(XP_OS2)
          {
             char buffer[CCHMAXPATH] = "";
             char *c = getenv( "TMP");
             if( c) strcpy( buffer, c);
             else
             {
                c = getenv( "TEMP");
                if( c) strcpy( buffer, c);
             }
             if( c) *this = buffer;
             // use exe's directory if not set
             else GetCurrentProcessDirectory(*this);
          }        
#elif defined(XP_UNIX) || defined(XP_BEOS)
		{
			static const char *tPath = nsnull;
			if (!tPath) {
				tPath = PR_GetEnv("TMPDIR");
				if (!tPath || !*tPath) {
					tPath = PR_GetEnv("TMP");
					if (!tPath || !*tPath) {
						tPath = PR_GetEnv("TEMP");
						if (!tPath || !*tPath) {
							tPath = "/tmp/";
						}
					}
				}
			}
			
			*this = tPath;
		}
#endif
        break;

        case OS_CurrentProcessDirectory:
            GetCurrentProcessDirectory(*this);
            break;

        case OS_CurrentWorkingDirectory:
            GetCurrentWorkingDirectory(*this);
            break;

        case XPCOM_CurrentProcessComponentRegistry:
            {
                nsFileSpec *dirSpec = NULL;

                // if someone has called nsSpecialSystemDirectory::Set()
                if (systemDirectoriesLocations) {
                    // look for the value for the argument key
                    if (!(dirSpec = (nsFileSpec *)systemDirectoriesLocations->Get(&dirKey))) {
                        // if not found, try Moz_BinDirectory
                        dirSpec = (nsFileSpec *)
                            systemDirectoriesLocations->Get(&mozBinDirKey);
                    }
                    else {
                        // if the value is found for the argument key,
                        // we don't need to append.
                        needToAppend = PR_FALSE;
                    }
                }
                
                if (dirSpec)
                {
                    *this = *dirSpec;
                }
                else
                {
                    GetCurrentProcessDirectory(*this);
                }

                if (needToAppend) {
                    // XXX We need to unify these names across all platforms
                    *this += "component.reg";
                }
            }
            break;

        case XPCOM_CurrentProcessComponentDirectory:
            {
                nsFileSpec *dirSpec = NULL;
                // if someone has called nsSpecialSystemDirectory::Set()
                if (systemDirectoriesLocations) {
                    // look for the value for the argument key
                    if (!(dirSpec = (nsFileSpec *)systemDirectoriesLocations->Get(&dirKey))) {
                        // if not found, try Moz_BinDirectory
                        dirSpec = (nsFileSpec *)
                            systemDirectoriesLocations->Get(&mozBinDirKey);
                    }
                    else {
                        // if the value is found for the argument key,
                        // we don't need to append.
                        needToAppend = PR_FALSE;
                    }
                }
                if (dirSpec)
                {
                    *this = *dirSpec;
                }
                else
                {
                    // <exedir>/Components
                    GetCurrentProcessDirectory(*this);
                }

                if (needToAppend) {
                    // XXX We need to unify these names across all platforms
                    *this += "components";
                }
            }
            break;

        case Moz_BinDirectory:
            {
                nsFileSpec *dirSpec = NULL;
                // if someone has called nsSpecialSystemDirectory::Set()
                if (systemDirectoriesLocations) {
                    // look for the value for the argument key
                    dirSpec = (nsFileSpec *)
                        systemDirectoriesLocations->Get(&dirKey);
                }
                if (dirSpec) {
                    *this = *dirSpec;
                }
                else {
                    GetCurrentProcessDirectory(*this);
                }
            }
            break;
            
#if defined (XP_WIN)
        case Win_SystemDirectory:
        {    
            char path[_MAX_PATH];
            PRInt32 len = GetSystemDirectory( path, _MAX_PATH );
        
            // Need enough space to add the trailing backslash
            if (len > _MAX_PATH-2)
                break;
            path[len]   = '\\';
            path[len+1] = '\0';

            *this = MakeUpperCase(path);

            break;
        }

        case Win_WindowsDirectory:
        {    
            char path[_MAX_PATH];
            PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
            
            // Need enough space to add the trailing backslash
            if (len > _MAX_PATH-2)
                break;
            
            path[len]   = '\\';
            path[len+1] = '\0';

            *this = MakeUpperCase(path);
            break;
        }

        case Win_HomeDirectory:
        {    
            char path[_MAX_PATH];
            if (GetEnvironmentVariable(TEXT("HOME"), path, _MAX_PATH) > 0)
            {
                PRInt32 len = PL_strlen(path);
                // Need enough space to add the trailing backslash
                if (len > _MAX_PATH - 2)
                    break;
               
                path[len]   = '\\';
                path[len+1] = '\0';
                
                *this = MakeUpperCase(path);
                break;
            }

            if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) > 0)
            {
                char temp[_MAX_PATH];
                if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)
                   PL_strcatn(path, _MAX_PATH, temp);
        
                PRInt32 len = PL_strlen(path);

                // Need enough space to add the trailing backslash
                if (len > _MAX_PATH - 2)
                    break;
            
                path[len]   = '\\';
                path[len+1] = '\0';
                
                *this = MakeUpperCase(path);
                break;
            }
        }
        case Win_Desktop:
        {
            GetWindowsFolder(CSIDL_DESKTOP, *this);
            break;
        }
        case Win_Programs:
        {
            GetWindowsFolder(CSIDL_PROGRAMS, *this);
            break;
        }
        case Win_Controls:
        {
            GetWindowsFolder(CSIDL_CONTROLS, *this);
            break;
        }
        case Win_Printers:
        {
            GetWindowsFolder(CSIDL_PRINTERS, *this);
            break;
        }
        case Win_Personal:
        {
            GetWindowsFolder(CSIDL_PERSONAL, *this);
            break;
        }
        case Win_Favorites:
        {
            GetWindowsFolder(CSIDL_FAVORITES, *this);
            break;
        }
        case Win_Startup:
        {
            GetWindowsFolder(CSIDL_STARTUP, *this);
            break;
        }
        case Win_Recent:
        {
            GetWindowsFolder(CSIDL_RECENT, *this);
            break;
        }
        case Win_Sendto:
        {
            GetWindowsFolder(CSIDL_SENDTO, *this);
            break;
        }
        case Win_Bitbucket:
        {
            GetWindowsFolder(CSIDL_BITBUCKET, *this);
            break;
        }
        case Win_Startmenu:
        {
            GetWindowsFolder(CSIDL_STARTMENU, *this);
            break;
        }
        case Win_Desktopdirectory:
        {
            GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, *this);
            break;
        }
        case Win_Drives:
        {
            GetWindowsFolder(CSIDL_DRIVES, *this);
            break;
        }
        case Win_Network:
        {
            GetWindowsFolder(CSIDL_NETWORK, *this);
            break;
        }
        case Win_Nethood:
        {
            GetWindowsFolder(CSIDL_NETHOOD, *this);
            break;
        }
        case Win_Fonts:
        {
            GetWindowsFolder(CSIDL_FONTS, *this);
            break;
        }
        case Win_Templates:
        {
            GetWindowsFolder(CSIDL_TEMPLATES, *this);
            break;
        }
#ifndef WINCE
        case Win_Common_Startmenu:
        {
            GetWindowsFolder(CSIDL_COMMON_STARTMENU, *this);
            break;
        }
        case Win_Common_Programs:
        {
            GetWindowsFolder(CSIDL_COMMON_PROGRAMS, *this);
            break;
        }
        case Win_Common_Startup:
        {
            GetWindowsFolder(CSIDL_COMMON_STARTUP, *this);
            break;
        }
        case Win_Common_Desktopdirectory:
        {
            GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, *this);
            break;
        }
        case Win_Printhood:
        {
            GetWindowsFolder(CSIDL_PRINTHOOD, *this);
            break;
        }
        case Win_Cookies:
        {
            GetWindowsFolder(CSIDL_COOKIES, *this);
            break;
        }
#endif // WINCE

        case Win_Appdata:
        {
            GetWindowsFolder(CSIDL_APPDATA, *this);
            break;
        }
#endif  // XP_WIN

#if defined(XP_UNIX)
        case Unix_LocalDirectory:
            *this = "/usr/local/netscape/";
            break;

        case Unix_LibDirectory:
            *this = "/usr/local/lib/netscape/";
            break;

        case Unix_HomeDirectory:
#ifdef VMS
	    {
	        char *pHome;
	        pHome = getenv("HOME");
		if (*pHome == '/')
        	    *this = pHome;
		else
        	    *this = decc$translate_vms(pHome);
	    }
#else
            *this = PR_GetEnv("HOME");
#endif
            break;

#endif        

#ifdef XP_BEOS
        case BeOS_SettingsDirectory:
		{
            char path[MAXPATHLEN];
			find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, path, MAXPATHLEN);
            // Need enough space to add the trailing backslash
			int len = strlen(path);
            if (len > MAXPATHLEN-2)
                break;
            path[len]   = '/';
            path[len+1] = '\0';
			*this = path;
            break;
		}

        case BeOS_HomeDirectory:
		{
            char path[MAXPATHLEN];
			find_directory(B_USER_DIRECTORY, 0, 0, path, MAXPATHLEN);
            // Need enough space to add the trailing backslash
			int len = strlen(path);
            if (len > MAXPATHLEN-2)
                break;
            path[len]   = '/';
            path[len+1] = '\0';
			*this = path;
            break;
		}

        case BeOS_DesktopDirectory:
		{
            char path[MAXPATHLEN];
			find_directory(B_DESKTOP_DIRECTORY, 0, 0, path, MAXPATHLEN);
            // Need enough space to add the trailing backslash
			int len = strlen(path);
            if (len > MAXPATHLEN-2)
                break;
            path[len]   = '/';
            path[len+1] = '\0';
			*this = path;
            break;
		}

        case BeOS_SystemDirectory:
		{
            char path[MAXPATHLEN];
			find_directory(B_BEOS_DIRECTORY, 0, 0, path, MAXPATHLEN);
            // Need enough space to add the trailing backslash
			int len = strlen(path);
            if (len > MAXPATHLEN-2)
                break;
            path[len]   = '/';
            path[len+1] = '\0';
			*this = path;
            break;
		}
#endif        
#ifdef XP_OS2
        case OS2_SystemDirectory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\System\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
            *this = buffer;
#ifdef DEBUG
            printf( "Got OS2_SystemDirectory: %s\n", buffer);
#endif
            break;
        }

     case OS2_OS2Directory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
            *this = buffer;
#ifdef DEBUG
            printf( "Got OS2_OS2Directory: %s\n", buffer);
#endif
            break;
        }

     case OS2_HomeDirectory:
        {
            char *tPath = PR_GetEnv("MOZILLA_HOME");
            /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */
            /* To ensure we get a long filename system */
            if (!tPath || !*tPath)
              GetCurrentProcessDirectory(*this);
            else
              *this = tPath;
            PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", *this);
            break;
        }

        case OS2_DesktopDirectory:
        {
            char szPath[CCHMAXPATH + 1];        
            BOOL fSuccess;
            fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath));
            int len = strlen (szPath);   
            if (len > CCHMAXPATH -1)
               break;
            szPath[len] = '\\';     
            szPath[len + 1] = '\0';
#ifdef DEBUG
            if (fSuccess) {
               printf ("Got OS2_DesktopDirectory: %s\n", szPath);
            } else {
               printf ("Failed getting OS2_DesktopDirectory: %s\n", szPath);
            }
#endif
            break;           
        }

#endif
        default:
            break;    
    }
}
Exemplo n.º 26
0
BOOL LoadNLS(VOID)
{
    BOOL Proceed = TRUE;

    if (PrfQueryProfileString(HINI_USER,
                              "XWorkplace",
                              "XFolderPath",
                              "",
                              G_szNLSDLL,
                              sizeof(G_szNLSDLL))
                   < 3)

    {
        DisplayError("NetscapeDDE was unable to determine the location of the "
                     "XWorkplace National Language Support DLL, which is "
                     "required for operation. The OS2.INI file does not contain "
                     "this information. "
                     "NetscapeDDE cannot proceed. Please re-install XWorkplace.");
        Proceed = FALSE;
    }
    else
    {
        CHAR    szLanguageCode[50] = "";

        // now compose module name from language code
        PrfQueryProfileString(HINI_USERPROFILE,
                              "XWorkplace", "Language",
                              "001",
                              (PVOID)szLanguageCode,
                              sizeof(szLanguageCode));
        // allow '?:\' for boot drive
        // V0.9.19 (2002-06-08) [umoeller]
        if (G_szNLSDLL[0] == '?')
        {
            ULONG ulBootDrive;
            DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                            &ulBootDrive,
                            sizeof(ulBootDrive));
            G_szNLSDLL[0] = (CHAR)ulBootDrive + 'A' - 1;
        }

        strcat(G_szNLSDLL, "\\bin\\xfldr");
        strcat(G_szNLSDLL, szLanguageCode);
        strcat(G_szNLSDLL, ".dll");

        // try to load the module
        if (DosLoadModule(NULL,
                          0,
                          G_szNLSDLL,
                          &G_hmodNLS))
        {
            DisplayError("NetscapeDDE was unable to load \"%s\", "
                         "the National Language DLL which "
                         "is specified for XWorkplace in OS2.INI.",
                         G_szNLSDLL);
            Proceed = FALSE;
        }
    }

    return Proceed;
}
Exemplo n.º 27
0
int RAND_poll (void)
{
    char failed_module[20];

    QWORD qwTime;

    ULONG SysVars[QSV_FOREGROUND_PROCESS];

    if (hDoscalls == 0)
    {
        ULONG rc = DosLoadModule (failed_module, sizeof (failed_module), "DOSCALLS", &hDoscalls);

#ifndef __KLIBC__
        if (rc == 0)
        {
            rc = DosQueryProcAddr (hDoscalls, 976, NULL, (PFN *) & DosPerfSysCall);

            if (rc)
                DosPerfSysCall = NULL;

            rc = DosQueryProcAddr (hDoscalls, 368, NULL, (PFN *) & DosQuerySysState);

            if (rc)
                DosQuerySysState = NULL;
        }
#endif
    }

    /* Sample the hi-res timer, runs at around 1.1 MHz */
    DosTmrQueryTime (&qwTime);
    RAND_add (&qwTime, sizeof (qwTime), 2);

    /* Sample a bunch of system variables, includes various process & memory statistics */
    DosQuerySysInfo (1, QSV_FOREGROUND_PROCESS, SysVars, sizeof (SysVars));
    RAND_add (SysVars, sizeof (SysVars), 4);

    /* If available, sample CPU registers that count at CPU MHz
     * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this
     */
    if (DosPerfSysCall)
    {
        CPUUTIL util;

        if (DosPerfSysCall (CMD_KI_RDCNT, (ULONG) & util, 0, 0) == 0)
        {
            RAND_add (&util, sizeof (util), 10);
        }
        else
        {
#ifndef __KLIBC__
            DosPerfSysCall = NULL;
#endif
        }
    }

    /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */
    if (DosQuerySysState)
    {
        char *buffer = OPENSSL_malloc (256 * 1024);

        if (DosQuerySysState (0x1F, 0, 0, 0, buffer, 256 * 1024) == 0)
        {
            /* First 4 bytes in buffer is a pointer to the thread count
             * there should be at least 1 byte of entropy per thread
             */
            RAND_add (buffer, 256 * 1024, **(ULONG **) buffer);
        }

        OPENSSL_free (buffer);
        return 1;
    }

    return 0;
}
Exemplo n.º 28
0
/*
** PR_GetNumberOfProcessors()
** 
** Implementation notes:
**   Every platform does it a bit different.
**     numCpus is the returned value.
**   for each platform's "if defined" section
**     declare your local variable
**     do your thing, assign to numCpus
**   order of the if defined()s may be important,
**     especially for unix variants. Do platform
**     specific implementations before XP_UNIX.
** 
*/
PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
{
    PRInt32     numCpus;
#if defined(WIN32)
    SYSTEM_INFO     info;

    GetSystemInfo( &info );
    numCpus = info.dwNumberOfProcessors;
#elif defined(BEOS)
    system_info sysInfo;

    get_system_info(&sysInfo);
    numCpus = sysInfo.cpu_count;
#elif defined(OS2)
    DosQuerySysInfo( QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numCpus, sizeof(numCpus));
#elif defined(_PR_HAVE_SYSCTL)
    int mib[2];
    int rc;
    size_t len = sizeof(numCpus);

    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;
    rc = sysctl( mib, 2, &numCpus, &len, NULL, 0 );
    if ( -1 == rc )  {
        numCpus = -1; /* set to -1 for return value on error */
        _PR_MD_MAP_DEFAULT_ERROR( _MD_ERRNO() );
    }
#elif defined(HPUX)
    numCpus = mpctl( MPC_GETNUMSPUS, 0, 0 );
    if ( numCpus < 1 )  {
        numCpus = -1; /* set to -1 for return value on error */
        _PR_MD_MAP_DEFAULT_ERROR( _MD_ERRNO() );
    }
#elif defined(IRIX)
    numCpus = sysconf( _SC_NPROC_ONLN );
#elif defined(RISCOS) || defined(SYMBIAN)
    numCpus = 1;
#elif defined(LINUX)
    /* for the benefit of devices with advanced power-saving, that
       actually hotplug their cpus in heavy load, try to figure out
       the real number of CPUs */
    char buf[MAX_LINE];
    FILE *fin;
    const char *cpu_present = "/sys/devices/system/cpu/present";
    size_t strsize;
    numCpus = 0;
    fin = fopen(cpu_present, "r");
    if (fin != NULL) {
        if (fgets(buf, MAX_LINE, fin) != NULL) {
            /* check that the format is what we expect */
            if (buf[0] == '0') {
                strsize = strlen(buf);
                if (strsize == 1) {
                    /* single core */
                    numCpus = 1;
                } else if (strsize >= 3 && strsize <= 5) {
                    /* should be of the form 0-999 */
                    /* parse the part after the 0-, note count is 0-based */
                    if (buf[1] == '-' && isdigit(buf[2])) {
                        numCpus = 1 + atoi(buf + 2);
                    }
                }
            }
        }
        fclose(fin);
    }
    /* if that fails, fall back to more standard methods */
    if (!numCpus) {
        numCpus = sysconf( _SC_NPROCESSORS_CONF );
    }
#elif defined(XP_UNIX)
    numCpus = sysconf( _SC_NPROCESSORS_CONF );
#else
#error "An implementation is required"
#endif
    return(numCpus);
} /* end PR_GetNumberOfProcessors() */
Exemplo n.º 29
0
char * hb_verPlatform( void )
{
   char * pszPlatform;

   HB_TRACE( HB_TR_DEBUG, ( "hb_verPlatform()" ) );

   pszPlatform = ( char * ) hb_xgrab( PLATFORM_BUF_SIZE + 1 );

#if defined( HB_OS_DOS )

   {
      union REGS regs;

      regs.h.ah = 0x30;
      HB_DOS_INT86( 0x21, &regs, &regs );

      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "DOS %d.%02d", regs.h.al, regs.h.ah );

      /* Host OS detection: Windows 2.x, 3.x, 95/98 */

      {
         regs.HB_XREGS.ax = 0x1600;
         HB_DOS_INT86( 0x2F, &regs, &regs );

         if( regs.h.al != 0x00 && regs.h.al != 0x80 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 0x01 || regs.h.al == 0xFF )
               hb_snprintf( szHost, sizeof( szHost ), " (Windows 2.x)" );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (Windows %d.%02d)", regs.h.al, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }

      /* Host OS detection: Windows NT family */

      {
         regs.HB_XREGS.ax = 0x3306;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.HB_XREGS.bx == 0x3205 )
            hb_strncat( pszPlatform, " (Windows NT)", PLATFORM_BUF_SIZE );
      }

      /* Host OS detection: OS/2 */

      {
         regs.h.ah = 0x30;
         HB_DOS_INT86( 0x21, &regs, &regs );

         if( regs.h.al >= 10 )
         {
            char szHost[ 128 ];

            if( regs.h.al == 20 && regs.h.ah > 20 )
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.ah / 10, regs.h.ah % 10 );
            else
               hb_snprintf( szHost, sizeof( szHost ), " (OS/2 %d.%02d)", regs.h.al / 10, regs.h.ah );

            hb_strncat( pszPlatform, szHost, PLATFORM_BUF_SIZE );
         }
      }
   }

#elif defined( HB_OS_OS2 )

   {
      unsigned long aulQSV[ QSV_MAX ] = { 0 };
      APIRET rc = DosQuerySysInfo( 1L, QSV_MAX, ( void * ) aulQSV, sizeof( ULONG ) * QSV_MAX );

      if( rc == 0 )
      {
         /* is this OS/2 2.x ? */
         if( aulQSV[ QSV_VERSION_MINOR - 1 ] < 30 )
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %ld.%02ld",
                         aulQSV[ QSV_VERSION_MAJOR - 1 ] / 10,
                         aulQSV[ QSV_VERSION_MINOR - 1 ] );
         else
            hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2 %2.2f",
                         ( float ) aulQSV[ QSV_VERSION_MINOR - 1 ] / 10 );
      }
      else
         hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "OS/2" );
   }

#elif defined( HB_OS_WIN )

   {
      const char * pszName = "";

      OSVERSIONINFO osvi;

      memset( &osvi, 0, sizeof( osvi ) );

#if defined( HB_OS_WIN_CE )
      pszName = " CE";
      osvi.dwOSVersionInfoSize = sizeof( osvi );
      GetVersionEx( &osvi );
#else
      /* Detection of legacy Windows versions */
      switch( hb_iswin9x() )
      {
         case 5:
            osvi.dwMajorVersion = 4;
            osvi.dwMinorVersion = 0;
            pszName = " 95";
            break;
         case 8:
            osvi.dwMajorVersion = 4;
            osvi.dwMinorVersion = 10;
            pszName = " 98";
            break;
         case 9:
            osvi.dwMajorVersion = 4;
            osvi.dwMinorVersion = 90;
            pszName = " ME";
            break;
      }
#endif

      if( pszName[ 0 ] == '\0' )
      {
#if defined( HB_OS_WIN_CE )
         pszName = " CE";
#else
         if( hb_iswinver( 11, 0, 0, HB_TRUE ) )
         {
            osvi.dwMajorVersion = 11;
            osvi.dwMinorVersion = 0;
            pszName = " 11 or newer";
         }
         else if( hb_iswin10() )
         {
            osvi.dwMajorVersion = 10;
            osvi.dwMinorVersion = 0;
            if( hb_iswinver( 10, 0, VER_NT_WORKSTATION, HB_FALSE ) )
               pszName = " 10";
            else
               pszName = " Server 2016";
         }
         else if( hb_iswin81() )
         {
            osvi.dwMajorVersion = 6;
            osvi.dwMinorVersion = 3;
            if( hb_iswinver( 6, 3, VER_NT_WORKSTATION, HB_FALSE ) )
               pszName = " 8.1";
            else
               pszName = " Server 2012 R2";
         }
         else if( hb_iswinvista() )
         {
            if( hb_iswin8() )
            {
               osvi.dwMajorVersion = 6;
               osvi.dwMinorVersion = 2;
               if( hb_iswinver( 6, 2, VER_NT_WORKSTATION, HB_FALSE ) )
                  pszName = " 8";
               else
                  pszName = " Server 2012";
            }
            else if( hb_iswinver( 6, 1, 0, HB_FALSE ) )
            {
               osvi.dwMajorVersion = 6;
               osvi.dwMinorVersion = 1;
               if( hb_iswinver( 6, 1, VER_NT_WORKSTATION, HB_FALSE ) )
                  pszName = " 7";
               else
                  pszName = " Server 2008 R2";
            }
            else
            {
               osvi.dwMajorVersion = 6;
               osvi.dwMinorVersion = 0;
               if( hb_iswinver( 6, 0, VER_NT_WORKSTATION, HB_FALSE ) )
                  pszName = " Vista";
               else
                  pszName = " Server 2008";
            }
         }
         else if( hb_iswinver( 5, 2, 0, HB_FALSE ) )
         {
            osvi.dwMajorVersion = 5;
            osvi.dwMinorVersion = 2;
            if( hb_iswinver( 5, 2, VER_NT_WORKSTATION, HB_FALSE ) )
               pszName = " XP x64";
            else if( GetSystemMetrics( SM_SERVERR2 ) != 0 )
               pszName = " Server 2003 R2";
            else
               pszName = " Server 2003";
         }
         else if( hb_iswinver( 5, 1, 0, HB_FALSE ) )
         {
            osvi.dwMajorVersion = 5;
            osvi.dwMinorVersion = 1;
            pszName = " XP";
         }
         else if( hb_iswin2k() )
         {
            osvi.dwMajorVersion = 5;
            osvi.dwMinorVersion = 0;
            pszName = " 2000";
         }
         else
            pszName = " NT";
#endif
      }

      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows%s%s %lu.%lu",
                   pszName,
                   s_iWine ? " (Wine)" : "",
                   osvi.dwMajorVersion,
                   osvi.dwMinorVersion );

      /* Add service pack/other info */

      if( hb_iswin2k() )
      {
         int tmp;

         for( tmp = 5; tmp > 0; --tmp )
         {
            if( hb_iswinsp( tmp, HB_TRUE ) )
            {
               char szServicePack[ 8 ];
               hb_snprintf( szServicePack, sizeof( szServicePack ), " SP%u", tmp );
               hb_strncat( pszPlatform, szServicePack, PLATFORM_BUF_SIZE );
               break;
            }
         }
      }
#if defined( HB_OS_WIN_CE )
      else
      {
         /* Also for Win9x and NT, but GetVersionEx() is deprecated
            so we avoid it. */
         if( osvi.szCSDVersion[ 0 ] != TEXT( '\0' ) )
         {
            char * pszCSDVersion = HB_OSSTRDUP( osvi.szCSDVersion );
            int i;

            /* Skip the leading spaces (Win95B, Win98) */
            for( i = 0; pszCSDVersion[ i ] != '\0' && HB_ISSPACE( ( int ) pszCSDVersion[ i ] ); i++ )
               ;

            if( pszCSDVersion[ i ] != '\0' )
            {
               hb_strncat( pszPlatform, " ", PLATFORM_BUF_SIZE );
               hb_strncat( pszPlatform, pszCSDVersion + i, PLATFORM_BUF_SIZE );
            }
            hb_xfree( pszCSDVersion );
         }
      }
#endif
   }

#elif defined( __CEGCC__ )
   {
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "Windows CE" );
   }
#elif defined( HB_OS_UNIX )

   {
      struct utsname un;

      uname( &un );
#if defined( HB_OS_MINIX )
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s Release %s Version %s %s",
                   un.sysname, un.release, un.version, un.machine );
#else
      hb_snprintf( pszPlatform, PLATFORM_BUF_SIZE + 1, "%s %s %s", un.sysname, un.release, un.machine );
#endif
   }

#else

   {
      hb_strncpy( pszPlatform, "(unrecognized)", PLATFORM_BUF_SIZE );
   }

#endif

   return pszPlatform;
}
Exemplo n.º 30
0
/*
** PR_GetPhysicalMemorySize()
** 
** Implementation notes:
**   Every platform does it a bit different.
**     bytes is the returned value.
**   for each platform's "if defined" section
**     declare your local variable
**     do your thing, assign to bytes.
** 
*/
PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
{
    PRUint64 bytes = 0;

#if defined(LINUX) || defined(SOLARIS)

    long pageSize = sysconf(_SC_PAGESIZE);
    long pageCount = sysconf(_SC_PHYS_PAGES);
    if (pageSize >= 0 && pageCount >= 0)
        bytes = (PRUint64) pageSize * pageCount;

#elif defined(NETBSD) || defined(OPENBSD)

    int mib[2];
    int rc;
    uint64_t memSize;
    size_t len = sizeof(memSize);

    mib[0] = CTL_HW;
    mib[1] = HW_PHYSMEM64;
    rc = sysctl(mib, 2, &memSize, &len, NULL, 0);
    if (-1 != rc)  {
        bytes = memSize;
    }

#elif defined(HPUX)

    struct pst_static info;
    int result = pstat_getstatic(&info, sizeof(info), 1, 0);
    if (result == 1)
        bytes = (PRUint64) info.physical_memory * info.page_size;

#elif defined(DARWIN)

    mach_port_t mach_host = mach_host_self();
    struct host_basic_info hInfo;
    mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;

    int result = host_info(mach_host,
                           HOST_BASIC_INFO,
                           (host_info_t) &hInfo,
                           &count);
    mach_port_deallocate(mach_task_self(), mach_host);
    if (result == KERN_SUCCESS)
        bytes = hInfo.max_mem;

#elif defined(WIN32)

    MEMORYSTATUSEX memStat;
    memStat.dwLength = sizeof(memStat);
    if (GlobalMemoryStatusEx(&memStat))
        bytes = memStat.ullTotalPhys;

#elif defined(OS2)

    ULONG ulPhysMem;
    DosQuerySysInfo(QSV_TOTPHYSMEM,
                    QSV_TOTPHYSMEM,
                    &ulPhysMem,
                    sizeof(ulPhysMem));
    bytes = ulPhysMem;

#elif defined(AIX)

    if (odm_initialize() == 0) {
        int how_many;
        struct CuAt *obj = getattr("sys0", "realmem", 0, &how_many);
        if (obj != NULL) {
            bytes = (PRUint64) atoi(obj->value) * 1024;
            free(obj);
        }
        odm_terminate();
    }

#else

    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);

#endif

    return bytes;
} /* end PR_GetPhysicalMemorySize() */