2004-10-22 20:06:05 +04:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-11-22 03:37:56 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
2004-10-22 20:06:05 +04:00
|
|
|
|
|
|
|
#ifndef OMPI_MISC_H
|
|
|
|
#define OMPI_MISC_H
|
|
|
|
|
2005-12-31 15:23:28 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#define _SC_PAGESIZE 0
|
2005-12-31 15:23:28 +03:00
|
|
|
#define _SC_OPEN_MAX 1
|
2004-10-22 20:06:05 +04:00
|
|
|
|
2006-08-27 08:53:52 +04:00
|
|
|
#if 0
|
2005-12-31 15:23:28 +03:00
|
|
|
/* currently, this is a memory leak */
|
|
|
|
static __inline char* getenv (const char *name)
|
|
|
|
{
|
2004-11-02 16:14:34 +03:00
|
|
|
int ret;
|
2005-12-31 15:23:28 +03:00
|
|
|
char *buffer;
|
2006-08-23 03:25:13 +04:00
|
|
|
DWORD length = GetEnvironmentVariable( (LPCSTR)name, NULL, 0 );
|
2005-12-31 15:23:28 +03:00
|
|
|
|
|
|
|
if( 0 == length ) return NULL;
|
|
|
|
buffer = (char *)malloc(sizeof(char) * length);
|
2006-08-23 03:25:13 +04:00
|
|
|
ret = GetEnvironmentVariable((LPCSTR)name, (LPSTR)buffer, length);
|
2004-11-02 16:14:34 +03:00
|
|
|
return (ret > 0) ? buffer: NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-23 03:25:13 +04:00
|
|
|
static __inline int setenv (const char *name, const char *value, int rewrite)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
if( 0 == rewrite ) {
|
|
|
|
DWORD length = 0;
|
|
|
|
if( 0 == (length = GetEnvironmentVariable( (LPCSTR)name, NULL, length )) ) {
|
|
|
|
if( ERROR_ENVVAR_NOT_FOUND == GetLastError() ) { /* do not exist */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-10-22 20:06:05 +04:00
|
|
|
/* just push it back to the windows thingy */
|
2006-08-23 03:25:13 +04:00
|
|
|
ret = SetEnvironmentVariable ((LPCSTR)name, (LPCSTR)value);
|
2004-10-22 20:06:05 +04:00
|
|
|
return (0 != ret)? 1: 0;
|
|
|
|
}
|
2006-08-27 08:53:52 +04:00
|
|
|
#endif
|
2004-10-22 20:06:05 +04:00
|
|
|
|
|
|
|
static __inline unsigned int sleep(unsigned int seconds) {
|
|
|
|
|
2006-08-23 03:25:13 +04:00
|
|
|
/* Allow interruptions */
|
2006-08-27 08:53:52 +04:00
|
|
|
SleepEx(seconds * 1000, TRUE);
|
2004-10-22 20:06:05 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this function can currently ONLY return the page size. for it to
|
2005-12-13 01:04:30 +03:00
|
|
|
do the entire sysconf range it needs to be extended */
|
2004-10-22 20:06:05 +04:00
|
|
|
static __inline size_t sysconf(int option) {
|
|
|
|
|
|
|
|
SYSTEM_INFO sys_info;
|
|
|
|
|
2006-08-23 03:25:13 +04:00
|
|
|
if( _SC_OPEN_MAX == option ) {
|
|
|
|
return _getmaxstdio();
|
|
|
|
}
|
2005-12-31 15:23:28 +03:00
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
GetSystemInfo(&sys_info);
|
|
|
|
if (_SC_PAGESIZE == option){
|
|
|
|
return (size_t)sys_info.dwPageSize;
|
|
|
|
}
|
2005-12-13 01:04:30 +03:00
|
|
|
printf( "This functionality is not supported: line: %d\tfile: %s\n",
|
2006-08-23 03:25:13 +04:00
|
|
|
__LINE__, __FILE__ );
|
2005-12-13 01:04:30 +03:00
|
|
|
abort();
|
|
|
|
return 0;
|
2004-10-22 20:06:05 +04:00
|
|
|
}
|
|
|
|
|
2004-10-28 22:13:43 +04:00
|
|
|
#define F_GETFL 0
|
|
|
|
#define F_SETFL 1
|
|
|
|
#define O_NONBLOCK 0
|
|
|
|
/*
|
|
|
|
* this function is currently defined only for setting the socket to be
|
|
|
|
* in the non-blocking mode. Else this function returns error not implemented.
|
|
|
|
* This calls ioctlsocket in the winsock library
|
|
|
|
*/
|
|
|
|
static __inline int fcntl (int fildes, int cmd, ...) {
|
|
|
|
int ret;
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
switch (cmd) {
|
2005-01-20 03:03:23 +03:00
|
|
|
case F_SETFL: mode = 1; ret = ioctlsocket ((SOCKET)fildes, FIONBIO, (u_long FAR*) &mode);
|
2004-10-28 22:13:43 +04:00
|
|
|
break;
|
|
|
|
case F_GETFL: ret = 0;
|
|
|
|
break;
|
|
|
|
default: printf("Option not supported: %d %s\n", __LINE__, __FILE__);
|
|
|
|
abort();
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-10-22 20:06:05 +04:00
|
|
|
#endif /* OMPI_MISC_H */
|