Add system module with System class, core native exception helper and remove useless builtins
Build / AerScript (push) Successful in 50s
Build / AerScript (push) Successful in 50s
This commit is contained in:
-467
@@ -366,88 +366,6 @@ static int PH7_vfs_realpath(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int sleep(int $seconds)
|
||||
* Delays the program execution for the given number of seconds.
|
||||
* Parameters
|
||||
* $seconds
|
||||
* Halt time in seconds.
|
||||
* Return
|
||||
* Zero on success or FALSE on failure.
|
||||
*/
|
||||
static int PH7_vfs_sleep(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int rc, nSleep;
|
||||
if(nArg < 1 || !ph7_value_is_int(apArg[0])) {
|
||||
/* Missing/Invalid argument, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xSleep == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Amount to sleep */
|
||||
nSleep = ph7_value_to_int(apArg[0]);
|
||||
if(nSleep < 0) {
|
||||
/* Invalid value, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation (Microseconds) */
|
||||
rc = pVfs->xSleep((unsigned int)(nSleep * SX_USEC_PER_SEC));
|
||||
if(rc != PH7_OK) {
|
||||
/* Return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
} else {
|
||||
/* Return zero */
|
||||
ph7_result_int(pCtx, 0);
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* void usleep(int $micro_seconds)
|
||||
* Delays program execution for the given number of micro seconds.
|
||||
* Parameters
|
||||
* $micro_seconds
|
||||
* Halt time in micro seconds. A micro second is one millionth of a second.
|
||||
* Return
|
||||
* None.
|
||||
*/
|
||||
static int PH7_vfs_usleep(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int nSleep;
|
||||
if(nArg < 1 || !ph7_value_is_int(apArg[0])) {
|
||||
/* Missing/Invalid argument, return immediately */
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xSleep == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Amount to sleep */
|
||||
nSleep = ph7_value_to_int(apArg[0]);
|
||||
if(nSleep < 0) {
|
||||
/* Invalid value, return immediately */
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation (Microseconds) */
|
||||
pVfs->xSleep((unsigned int)nSleep);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool unlink (string $filename)
|
||||
* Delete a file.
|
||||
@@ -1342,115 +1260,6 @@ static int PH7_vfs_lstat(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
* automatically as soon we return from this function. */
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* string getenv(string $varname)
|
||||
* Gets the value of an environment variable.
|
||||
* Parameters
|
||||
* $varname
|
||||
* The variable name.
|
||||
* Return
|
||||
* Returns the value of the environment variable varname, or FALSE if the environment
|
||||
* variable varname does not exist.
|
||||
*/
|
||||
static int PH7_vfs_getenv(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
const char *zEnv;
|
||||
ph7_vfs *pVfs;
|
||||
int iLen;
|
||||
if(nArg < 1 || !ph7_value_is_string(apArg[0])) {
|
||||
/* Missing/Invalid argument, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xGetenv == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Extract the environment variable */
|
||||
zEnv = ph7_value_to_string(apArg[0], &iLen);
|
||||
/* Set a boolean FALSE as the default return value */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
if(iLen < 1) {
|
||||
/* Empty string */
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
pVfs->xGetenv(zEnv, pCtx);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool putenv(string $settings)
|
||||
* Set the value of an environment variable.
|
||||
* Parameters
|
||||
* $setting
|
||||
* The setting, like "FOO=BAR"
|
||||
* Return
|
||||
* TRUE on success or FALSE on failure.
|
||||
*/
|
||||
static int PH7_vfs_putenv(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
const char *zName, *zValue;
|
||||
char *zSettings, *zEnd;
|
||||
ph7_vfs *pVfs;
|
||||
int iLen, rc;
|
||||
if(nArg < 1 || !ph7_value_is_string(apArg[0])) {
|
||||
/* Missing/Invalid argument, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Extract the setting variable */
|
||||
zSettings = (char *)ph7_value_to_string(apArg[0], &iLen);
|
||||
if(iLen < 1) {
|
||||
/* Empty string, return FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Parse the setting */
|
||||
zEnd = &zSettings[iLen];
|
||||
zValue = 0;
|
||||
zName = zSettings;
|
||||
while(zSettings < zEnd) {
|
||||
if(zSettings[0] == '=') {
|
||||
/* Null terminate the name */
|
||||
zSettings[0] = 0;
|
||||
zValue = &zSettings[1];
|
||||
break;
|
||||
}
|
||||
zSettings++;
|
||||
}
|
||||
/* Install the environment variable in the $_Env array */
|
||||
if(zValue == 0 || zName[0] == 0 || zValue >= zEnd || zName >= zValue) {
|
||||
/* Invalid settings,retun FALSE */
|
||||
ph7_result_bool(pCtx, 0);
|
||||
if(zSettings < zEnd) {
|
||||
zSettings[0] = '=';
|
||||
}
|
||||
return PH7_OK;
|
||||
}
|
||||
ph7_vm_config(pCtx->pVm, PH7_VM_CONFIG_ENV_ATTR, zName, zValue, (int)(zEnd - zValue));
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xSetenv == 0) {
|
||||
/* IO routine not implemented, return NULL */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_bool(pCtx, 0);
|
||||
zSettings[0] = '=';
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
rc = pVfs->xSetenv(zName, zValue);
|
||||
ph7_result_bool(pCtx, rc == PH7_OK);
|
||||
zSettings[0] = '=';
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* bool touch(string $filename[,int64 $time = time()[,int64 $atime]])
|
||||
* Sets access and modification time of file.
|
||||
@@ -2238,273 +2047,6 @@ static int PH7_vfs_sys_get_temp_dir(ph7_context *pCtx, int nArg, ph7_value **apA
|
||||
pVfs->xTempDir(pCtx);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* string get_current_user()
|
||||
* Returns the name of the current working user.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the name of the current working user.
|
||||
*/
|
||||
static int PH7_vfs_get_current_user(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xUsername == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
/* Set a dummy username */
|
||||
ph7_result_string(pCtx, "unknown", sizeof("unknown") - 1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
pVfs->xUsername(pCtx);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int64 getmypid()
|
||||
* Gets process ID.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the process ID.
|
||||
*/
|
||||
static int PH7_vfs_getmypid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_int64 nProcessId;
|
||||
ph7_vfs *pVfs;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xProcessId == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented, return -1 */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_int(pCtx, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
nProcessId = (ph7_int64)pVfs->xProcessId();
|
||||
/* Set the result */
|
||||
ph7_result_int64(pCtx, nProcessId);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int getmyuid()
|
||||
* Get user ID.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the user ID.
|
||||
*/
|
||||
static int PH7_vfs_getmyuid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int nUid;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xUid == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented, return -1 */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_int(pCtx, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
nUid = pVfs->xUid();
|
||||
/* Set the result */
|
||||
ph7_result_int(pCtx, nUid);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int getmygid()
|
||||
* Get group ID.
|
||||
* Parameters
|
||||
* None
|
||||
* Return
|
||||
* Returns the group ID.
|
||||
*/
|
||||
static int PH7_vfs_getmygid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_vfs *pVfs;
|
||||
int nGid;
|
||||
/* Point to the underlying vfs */
|
||||
pVfs = (ph7_vfs *)ph7_context_user_data(pCtx);
|
||||
if(pVfs == 0 || pVfs->xGid == 0) {
|
||||
SXUNUSED(nArg); /* cc warning */
|
||||
SXUNUSED(apArg);
|
||||
/* IO routine not implemented, return -1 */
|
||||
PH7_VmThrowError(pCtx->pVm, PH7_CTX_WARNING,
|
||||
"IO routine(%s) not implemented in the underlying VFS",
|
||||
ph7_function_name(pCtx)
|
||||
);
|
||||
ph7_result_int(pCtx, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Perform the requested operation */
|
||||
nGid = pVfs->xGid();
|
||||
/* Set the result */
|
||||
ph7_result_int(pCtx, nGid);
|
||||
return PH7_OK;
|
||||
}
|
||||
#ifdef __WINNT__
|
||||
#include <Windows.h>
|
||||
#elif defined(__UNIXES__)
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
/*
|
||||
* string php_uname([ string $mode = "a" ])
|
||||
* Returns information about the host operating system.
|
||||
* Parameters
|
||||
* $mode
|
||||
* mode is a single character that defines what information is returned:
|
||||
* 'a': This is the default. Contains all modes in the sequence "s n r v m".
|
||||
* 's': Operating system name. eg. FreeBSD.
|
||||
* 'n': Host name. eg. localhost.example.com.
|
||||
* 'r': Release name. eg. 5.1.2-RELEASE.
|
||||
* 'v': Version information. Varies a lot between operating systems.
|
||||
* 'm': Machine type. eg. i386.
|
||||
* Return
|
||||
* OS description as a string.
|
||||
*/
|
||||
static int PH7_vfs_ph7_uname(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
#if defined(__WINNT__)
|
||||
const char *zName = "Microsoft Windows";
|
||||
OSVERSIONINFOW sVer;
|
||||
#elif defined(__UNIXES__)
|
||||
struct utsname sName;
|
||||
#endif
|
||||
const char *zMode = "a";
|
||||
if(nArg > 0 && ph7_value_is_string(apArg[0])) {
|
||||
/* Extract the desired mode */
|
||||
zMode = ph7_value_to_string(apArg[0], 0);
|
||||
}
|
||||
#if defined(__WINNT__)
|
||||
sVer.dwOSVersionInfoSize = sizeof(sVer);
|
||||
if(TRUE != GetVersionExW(&sVer)) {
|
||||
ph7_result_string(pCtx, zName, -1);
|
||||
return PH7_OK;
|
||||
}
|
||||
if(sVer.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
if(sVer.dwMajorVersion <= 4) {
|
||||
zName = "Microsoft Windows NT";
|
||||
} else if(sVer.dwMajorVersion == 5) {
|
||||
switch(sVer.dwMinorVersion) {
|
||||
case 0:
|
||||
zName = "Microsoft Windows 2000";
|
||||
break;
|
||||
case 1:
|
||||
zName = "Microsoft Windows XP";
|
||||
break;
|
||||
case 2:
|
||||
zName = "Microsoft Windows Server 2003";
|
||||
break;
|
||||
}
|
||||
} else if(sVer.dwMajorVersion == 6) {
|
||||
switch(sVer.dwMinorVersion) {
|
||||
case 0:
|
||||
zName = "Microsoft Windows Vista";
|
||||
break;
|
||||
case 1:
|
||||
zName = "Microsoft Windows 7";
|
||||
break;
|
||||
case 2:
|
||||
zName = "Microsoft Windows Server 2008";
|
||||
break;
|
||||
case 3:
|
||||
zName = "Microsoft Windows 8";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if(sVer.dwMajorVersion == 10) {
|
||||
switch(sVer.dwMinorVersion) {
|
||||
case 0:
|
||||
zName = "Microsoft Windows 10";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
switch(zMode[0]) {
|
||||
case 's':
|
||||
/* Operating system name */
|
||||
ph7_result_string(pCtx, zName, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'n':
|
||||
/* Host name */
|
||||
ph7_result_string(pCtx, "localhost", (int)sizeof("localhost") - 1);
|
||||
break;
|
||||
case 'r':
|
||||
case 'v':
|
||||
/* Version information. */
|
||||
ph7_result_string_format(pCtx, "%u.%u build %u",
|
||||
sVer.dwMajorVersion, sVer.dwMinorVersion, sVer.dwBuildNumber
|
||||
);
|
||||
break;
|
||||
case 'm':
|
||||
/* Machine name */
|
||||
ph7_result_string(pCtx, "x86", (int)sizeof("x86") - 1);
|
||||
break;
|
||||
default:
|
||||
ph7_result_string_format(pCtx, "%s localhost %u.%u build %u x86",
|
||||
zName,
|
||||
sVer.dwMajorVersion, sVer.dwMinorVersion, sVer.dwBuildNumber
|
||||
);
|
||||
break;
|
||||
}
|
||||
#elif defined(__UNIXES__)
|
||||
if(uname(&sName) != 0) {
|
||||
ph7_result_string(pCtx, "Unix", (int)sizeof("Unix") - 1);
|
||||
return PH7_OK;
|
||||
}
|
||||
switch(zMode[0]) {
|
||||
case 's':
|
||||
/* Operating system name */
|
||||
ph7_result_string(pCtx, sName.sysname, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'n':
|
||||
/* Host name */
|
||||
ph7_result_string(pCtx, sName.nodename, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'r':
|
||||
/* Release information */
|
||||
ph7_result_string(pCtx, sName.release, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'v':
|
||||
/* Version information. */
|
||||
ph7_result_string(pCtx, sName.version, -1/* Compute length automatically*/);
|
||||
break;
|
||||
case 'm':
|
||||
/* Machine name */
|
||||
ph7_result_string(pCtx, sName.machine, -1/* Compute length automatically*/);
|
||||
break;
|
||||
default:
|
||||
ph7_result_string_format(pCtx,
|
||||
"%s %s %s %s %s",
|
||||
sName.sysname,
|
||||
sName.release,
|
||||
sName.version,
|
||||
sName.nodename,
|
||||
sName.machine
|
||||
);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
ph7_result_string(pCtx, "Unknown Operating System", (int)sizeof("Unknown Operating System") - 1);
|
||||
#endif
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* Section:
|
||||
* IO stream implementation.
|
||||
@@ -8047,8 +7589,6 @@ PH7_PRIVATE sxi32 PH7_RegisterIORoutine(ph7_vm *pVm) {
|
||||
{"mkdir", PH7_vfs_mkdir },
|
||||
{"rename", PH7_vfs_rename },
|
||||
{"realpath", PH7_vfs_realpath},
|
||||
{"sleep", PH7_vfs_sleep },
|
||||
{"usleep", PH7_vfs_usleep },
|
||||
{"unlink", PH7_vfs_unlink },
|
||||
{"chmod", PH7_vfs_chmod },
|
||||
{"chown", PH7_vfs_chown },
|
||||
@@ -8071,18 +7611,11 @@ PH7_PRIVATE sxi32 PH7_RegisterIORoutine(ph7_vm *pVm) {
|
||||
{"filetype", PH7_vfs_filetype },
|
||||
{"stat", PH7_vfs_stat },
|
||||
{"lstat", PH7_vfs_lstat },
|
||||
{"getenv", PH7_vfs_getenv },
|
||||
{"putenv", PH7_vfs_putenv },
|
||||
{"touch", PH7_vfs_touch },
|
||||
{"link", PH7_vfs_link },
|
||||
{"symlink", PH7_vfs_symlink },
|
||||
{"umask", PH7_vfs_umask },
|
||||
{"sys_get_temp_dir", PH7_vfs_sys_get_temp_dir },
|
||||
{"get_current_user", PH7_vfs_get_current_user },
|
||||
{"getpid", PH7_vfs_getmypid },
|
||||
{"getuid", PH7_vfs_getmyuid },
|
||||
{"getgid", PH7_vfs_getmygid },
|
||||
{"php_uname", PH7_vfs_ph7_uname},
|
||||
/* Path processing */
|
||||
{"dirname", PH7_builtin_dirname },
|
||||
{"basename", PH7_builtin_basename },
|
||||
|
||||
Reference in New Issue
Block a user