UnQLite
view release on metacpan or search on metacpan
unqlite/unqlite.c view on Meta::CPAN
/* IO routine not implemented, return NULL */
jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING,
"IO routine(%s) not implemented in the underlying VFS, JX9 is returning FALSE",
jx9_function_name(pCtx)
);
jx9_result_bool(pCtx, 0);
return JX9_OK;
}
/* Point to the desired directory */
zPath = jx9_value_to_string(apArg[0], 0);
/* Perform the requested operation */
rc = pVfs->xUnlink(zPath);
/* IO return value */
jx9_result_bool(pCtx, rc == JX9_OK);
return JX9_OK;
}
/*
* bool chmod(string $filename, int $mode)
* Attempts to change the mode of the specified file to that given in mode.
* Parameters
* $filename
* Path to the file.
* $mode
* Mode (Must be an integer)
* Return
* TRUE on success or FALSE on failure.
*/
static int jx9Vfs_chmod(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
const char *zPath;
jx9_vfs *pVfs;
int iMode;
int rc;
if( nArg < 2 || !jx9_value_is_string(apArg[0]) ){
/* Missing/Invalid argument, return FALSE */
jx9_result_bool(pCtx, 0);
return JX9_OK;
}
/* Point to the underlying vfs */
pVfs = (jx9_vfs *)jx9_context_user_data(pCtx);
if( pVfs == 0 || pVfs->xChmod == 0 ){
/* IO routine not implemented, return NULL */
jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING,
"IO routine(%s) not implemented in the underlying VFS, JX9 is returning FALSE",
jx9_function_name(pCtx)
);
jx9_result_bool(pCtx, 0);
return JX9_OK;
}
/* Point to the desired directory */
zPath = jx9_value_to_string(apArg[0], 0);
/* Extract the mode */
iMode = jx9_value_to_int(apArg[1]);
/* Perform the requested operation */
rc = pVfs->xChmod(zPath, iMode);
/* IO return value */
jx9_result_bool(pCtx, rc == JX9_OK);
return JX9_OK;
}
/*
* bool chown(string $filename, string $user)
* Attempts to change the owner of the file filename to user user.
* Parameters
* $filename
* Path to the file.
* $user
* Username.
* Return
* TRUE on success or FALSE on failure.
*/
static int jx9Vfs_chown(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
const char *zPath, *zUser;
jx9_vfs *pVfs;
int rc;
if( nArg < 2 || !jx9_value_is_string(apArg[0]) ){
/* Missing/Invalid arguments, return FALSE */
jx9_result_bool(pCtx, 0);
return JX9_OK;
}
/* Point to the underlying vfs */
pVfs = (jx9_vfs *)jx9_context_user_data(pCtx);
if( pVfs == 0 || pVfs->xChown == 0 ){
/* IO routine not implemented, return NULL */
jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING,
"IO routine(%s) not implemented in the underlying VFS, JX9 is returning FALSE",
jx9_function_name(pCtx)
);
jx9_result_bool(pCtx, 0);
return JX9_OK;
}
/* Point to the desired directory */
zPath = jx9_value_to_string(apArg[0], 0);
/* Extract the user */
zUser = jx9_value_to_string(apArg[1], 0);
/* Perform the requested operation */
rc = pVfs->xChown(zPath, zUser);
/* IO return value */
jx9_result_bool(pCtx, rc == JX9_OK);
return JX9_OK;
}
/*
* bool chgrp(string $filename, string $group)
* Attempts to change the group of the file filename to group.
* Parameters
* $filename
* Path to the file.
* $group
* groupname.
* Return
* TRUE on success or FALSE on failure.
*/
static int jx9Vfs_chgrp(jx9_context *pCtx, int nArg, jx9_value **apArg)
{
const char *zPath, *zGroup;
jx9_vfs *pVfs;
int rc;
if( nArg < 2 || !jx9_value_is_string(apArg[0]) ){
/* Missing/Invalid arguments, return FALSE */
jx9_result_bool(pCtx, 0);
return JX9_OK;
}
/* Point to the underlying vfs */
pVfs = (jx9_vfs *)jx9_context_user_data(pCtx);
if( pVfs == 0 || pVfs->xChgrp == 0 ){
/* IO routine not implemented, return NULL */
jx9_context_throw_error_format(pCtx, JX9_CTX_WARNING,
"IO routine(%s) not implemented in the underlying VFS, JX9 is returning FALSE",
jx9_function_name(pCtx)
);
jx9_result_bool(pCtx, 0);
unqlite/unqlite.c view on Meta::CPAN
if( rc != 0 ){
return -1;
}
/* dev */
jx9_value_int64(pWorker, (jx9_int64)st.st_dev);
jx9_array_add_strkey_elem(pArray, "dev", pWorker); /* Will make it's own copy */
/* ino */
jx9_value_int64(pWorker, (jx9_int64)st.st_ino);
jx9_array_add_strkey_elem(pArray, "ino", pWorker); /* Will make it's own copy */
/* mode */
jx9_value_int(pWorker, (int)st.st_mode);
jx9_array_add_strkey_elem(pArray, "mode", pWorker);
/* nlink */
jx9_value_int(pWorker, (int)st.st_nlink);
jx9_array_add_strkey_elem(pArray, "nlink", pWorker); /* Will make it's own copy */
/* uid, gid, rdev */
jx9_value_int(pWorker, (int)st.st_uid);
jx9_array_add_strkey_elem(pArray, "uid", pWorker);
jx9_value_int(pWorker, (int)st.st_gid);
jx9_array_add_strkey_elem(pArray, "gid", pWorker);
jx9_value_int(pWorker, (int)st.st_rdev);
jx9_array_add_strkey_elem(pArray, "rdev", pWorker);
/* size */
jx9_value_int64(pWorker, (jx9_int64)st.st_size);
jx9_array_add_strkey_elem(pArray, "size", pWorker); /* Will make it's own copy */
/* atime */
jx9_value_int64(pWorker, (jx9_int64)st.st_atime);
jx9_array_add_strkey_elem(pArray, "atime", pWorker); /* Will make it's own copy */
/* mtime */
jx9_value_int64(pWorker, (jx9_int64)st.st_mtime);
jx9_array_add_strkey_elem(pArray, "mtime", pWorker); /* Will make it's own copy */
/* ctime */
jx9_value_int64(pWorker, (jx9_int64)st.st_ctime);
jx9_array_add_strkey_elem(pArray, "ctime", pWorker); /* Will make it's own copy */
/* blksize, blocks */
jx9_value_int(pWorker, (int)st.st_blksize);
jx9_array_add_strkey_elem(pArray, "blksize", pWorker);
jx9_value_int(pWorker, (int)st.st_blocks);
jx9_array_add_strkey_elem(pArray, "blocks", pWorker);
return JX9_OK;
}
/* int (*xChmod)(const char *, int) */
static int UnixVfs_Chmod(const char *zPath, int mode)
{
int rc;
rc = chmod(zPath, (mode_t)mode);
return rc == 0 ? JX9_OK : - 1;
}
/* int (*xChown)(const char *, const char *) */
static int UnixVfs_Chown(const char *zPath, const char *zUser)
{
#ifndef JX9_UNIX_STATIC_BUILD
struct passwd *pwd;
uid_t uid;
int rc;
pwd = getpwnam(zUser); /* Try getting UID for username */
if (pwd == 0) {
return -1;
}
uid = pwd->pw_uid;
rc = chown(zPath, uid, -1);
return rc == 0 ? JX9_OK : -1;
#else
SXUNUSED(zPath);
SXUNUSED(zUser);
return -1;
#endif /* JX9_UNIX_STATIC_BUILD */
}
/* int (*xChgrp)(const char *, const char *) */
static int UnixVfs_Chgrp(const char *zPath, const char *zGroup)
{
#ifndef JX9_UNIX_STATIC_BUILD
struct group *group;
gid_t gid;
int rc;
group = getgrnam(zGroup);
if (group == 0) {
return -1;
}
gid = group->gr_gid;
rc = chown(zPath, -1, gid);
return rc == 0 ? JX9_OK : -1;
#else
SXUNUSED(zPath);
SXUNUSED(zGroup);
return -1;
#endif /* JX9_UNIX_STATIC_BUILD */
}
/* int (*xIsfile)(const char *) */
static int UnixVfs_isfile(const char *zPath)
{
struct stat st;
int rc;
rc = stat(zPath, &st);
if( rc != 0 ){
return -1;
}
rc = S_ISREG(st.st_mode);
return rc ? JX9_OK : -1 ;
}
/* int (*xIslink)(const char *) */
static int UnixVfs_islink(const char *zPath)
{
struct stat st;
int rc;
rc = stat(zPath, &st);
if( rc != 0 ){
return -1;
}
rc = S_ISLNK(st.st_mode);
return rc ? JX9_OK : -1 ;
}
/* int (*xReadable)(const char *) */
static int UnixVfs_isreadable(const char *zPath)
{
int rc;
rc = access(zPath, R_OK);
return rc == 0 ? JX9_OK : -1;
}
/* int (*xWritable)(const char *) */
static int UnixVfs_iswritable(const char *zPath)
{
int rc;
rc = access(zPath, W_OK);
return rc == 0 ? JX9_OK : -1;
}
/* int (*xExecutable)(const char *) */
static int UnixVfs_isexecutable(const char *zPath)
{
int rc;
rc = access(zPath, X_OK);
return rc == 0 ? JX9_OK : -1;
}
/* int (*xFiletype)(const char *, jx9_context *) */
static int UnixVfs_Filetype(const char *zPath, jx9_context *pCtx)
{
struct stat st;
int rc;
rc = stat(zPath, &st);
if( rc != 0 ){
/* Expand 'unknown' */
unqlite/unqlite.c view on Meta::CPAN
/* Export the jx9:// stream */
static const jx9_io_stream sjx9Stream = {
"jx9",
JX9_IO_STREAM_VERSION,
JX9StreamData_Open, /* xOpen */
0, /* xOpenDir */
JX9StreamData_Close, /* xClose */
0, /* xCloseDir */
JX9StreamData_Read, /* xRead */
0, /* xReadDir */
JX9StreamData_Write, /* xWrite */
0, /* xSeek */
0, /* xLock */
0, /* xRewindDir */
0, /* xTell */
0, /* xTrunc */
0, /* xSeek */
0 /* xStat */
};
#endif /* JX9_DISABLE_DISK_IO */
/*
* Return TRUE if we are dealing with the jx9:// stream.
* FALSE otherwise.
*/
static int is_jx9_stream(const jx9_io_stream *pStream)
{
#ifndef JX9_DISABLE_DISK_IO
return pStream == &sjx9Stream;
#else
SXUNUSED(pStream); /* cc warning */
return 0;
#endif /* JX9_DISABLE_DISK_IO */
}
#endif /* JX9_DISABLE_BUILTIN_FUNC */
/*
* Export the IO routines defined above and the built-in IO streams
* [i.e: file://, jx9://].
* Note:
* If the engine is compiled with the JX9_DISABLE_BUILTIN_FUNC directive
* defined then this function is a no-op.
*/
JX9_PRIVATE sxi32 jx9RegisterIORoutine(jx9_vm *pVm)
{
#ifndef JX9_DISABLE_BUILTIN_FUNC
/* VFS functions */
static const jx9_builtin_func aVfsFunc[] = {
{"chdir", jx9Vfs_chdir },
{"chroot", jx9Vfs_chroot },
{"getcwd", jx9Vfs_getcwd },
{"rmdir", jx9Vfs_rmdir },
{"is_dir", jx9Vfs_is_dir },
{"mkdir", jx9Vfs_mkdir },
{"rename", jx9Vfs_rename },
{"realpath", jx9Vfs_realpath},
{"sleep", jx9Vfs_sleep },
{"usleep", jx9Vfs_usleep },
{"unlink", jx9Vfs_unlink },
{"delete", jx9Vfs_unlink },
{"chmod", jx9Vfs_chmod },
{"chown", jx9Vfs_chown },
{"chgrp", jx9Vfs_chgrp },
{"disk_free_space", jx9Vfs_disk_free_space },
{"disk_total_space", jx9Vfs_disk_total_space},
{"file_exists", jx9Vfs_file_exists },
{"filesize", jx9Vfs_file_size },
{"fileatime", jx9Vfs_file_atime },
{"filemtime", jx9Vfs_file_mtime },
{"filectime", jx9Vfs_file_ctime },
{"is_file", jx9Vfs_is_file },
{"is_link", jx9Vfs_is_link },
{"is_readable", jx9Vfs_is_readable },
{"is_writable", jx9Vfs_is_writable },
{"is_executable", jx9Vfs_is_executable},
{"filetype", jx9Vfs_filetype },
{"stat", jx9Vfs_stat },
{"lstat", jx9Vfs_lstat },
{"getenv", jx9Vfs_getenv },
{"setenv", jx9Vfs_putenv },
{"putenv", jx9Vfs_putenv },
{"touch", jx9Vfs_touch },
{"link", jx9Vfs_link },
{"symlink", jx9Vfs_symlink },
{"umask", jx9Vfs_umask },
{"sys_get_temp_dir", jx9Vfs_sys_get_temp_dir },
{"get_current_user", jx9Vfs_get_current_user },
{"getpid", jx9Vfs_getmypid },
{"getuid", jx9Vfs_getmyuid },
{"getgid", jx9Vfs_getmygid },
{"uname", jx9Vfs_uname},
/* Path processing */
{"dirname", jx9Builtin_dirname },
{"basename", jx9Builtin_basename },
{"pathinfo", jx9Builtin_pathinfo },
{"strglob", jx9Builtin_strglob },
{"fnmatch", jx9Builtin_fnmatch },
/* ZIP processing */
{"zip_open", jx9Builtin_zip_open },
{"zip_close", jx9Builtin_zip_close},
{"zip_read", jx9Builtin_zip_read },
{"zip_entry_open", jx9Builtin_zip_entry_open },
{"zip_entry_close", jx9Builtin_zip_entry_close},
{"zip_entry_name", jx9Builtin_zip_entry_name },
{"zip_entry_filesize", jx9Builtin_zip_entry_filesize },
{"zip_entry_compressedsize", jx9Builtin_zip_entry_compressedsize },
{"zip_entry_read", jx9Builtin_zip_entry_read },
{"zip_entry_reset_cursor", jx9Builtin_zip_entry_reset_cursor},
{"zip_entry_compressionmethod", jx9Builtin_zip_entry_compressionmethod}
};
/* IO stream functions */
static const jx9_builtin_func aIOFunc[] = {
{"ftruncate", jx9Builtin_ftruncate },
{"fseek", jx9Builtin_fseek },
{"ftell", jx9Builtin_ftell },
{"rewind", jx9Builtin_rewind },
{"fflush", jx9Builtin_fflush },
{"feof", jx9Builtin_feof },
{"fgetc", jx9Builtin_fgetc },
{"fgets", jx9Builtin_fgets },
{"fread", jx9Builtin_fread },
{"fgetcsv", jx9Builtin_fgetcsv},
( run in 2.978 seconds using v1.01-cache-2.11-cpan-5511b514fd6 )