mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
160 lines
3.5 KiB
JavaScript
160 lines
3.5 KiB
JavaScript
clite.libs.data = function() {
|
|
|
|
clite.libs.load('libstd','stdlib',function(io,env) {
|
|
|
|
var pwentind = 0;
|
|
var grentind = 0;
|
|
|
|
return Object.create({
|
|
|
|
// returns the file name of a path /tmp/test/foo = foo
|
|
basename:function(txt) {
|
|
var parts = txt.split('/');
|
|
return parts[parts.length-1];
|
|
},
|
|
|
|
// returns the directory name of a path /tmp/test/foo = /tmp/test
|
|
dirname:function(txt) {
|
|
var parts = txt.split('/');
|
|
parts.pop();
|
|
return parts.join('/');
|
|
},
|
|
|
|
crypt:function(str,salt) {
|
|
return clite.lib.hash(str.toString()+':'+salt.toString());
|
|
},
|
|
|
|
// returns system info
|
|
uname:function() {
|
|
return Object.create({
|
|
sysname:'CLIte',
|
|
nodename:clite.core.hostname(),
|
|
release:clite.state.version,
|
|
version:clite.state.version,
|
|
machine:navigator.userAgent
|
|
});
|
|
},
|
|
|
|
// creates a new process
|
|
fork:function(env,io,call) {
|
|
return clite.lib.fork(env,io,call);
|
|
},
|
|
|
|
// executes a new program, replacing the current one
|
|
exec:function(path,args,env,io) {
|
|
return clite.lib.exec(path,args,env,io);
|
|
},
|
|
|
|
// exits the current program
|
|
exit:function(pid,v) {
|
|
io.exit(pid,v);
|
|
},
|
|
|
|
// returns the current user id
|
|
getuid:function() {
|
|
return clite.proc.getRUID(io.pid);
|
|
},
|
|
geteuid:function() {
|
|
return clite.proc.getUID(io.pid);
|
|
},
|
|
setuid:function(uid) {
|
|
if (!clite.proc.setRUID(io.pid,uid,false))
|
|
return false;
|
|
return clite.proc.setUID(io.pid,uid,false);
|
|
},
|
|
setreuid:function(ruid,euid) {
|
|
if (!clite.proc.setRUID(io.pid,ruid,false))
|
|
return false;
|
|
return clite.proc.setUID(io.pid,euid,false);
|
|
},
|
|
|
|
// gets the passwd file data for a user based on their uid
|
|
getpwuid:function(uid) {
|
|
return clite.user.getPWData(uid);
|
|
},
|
|
// gets the passwd file data for a user based on their name
|
|
getpwnam:function(name) {
|
|
var uid = clite.user.mapUserName(name);
|
|
if (uid < 0)
|
|
return null;
|
|
return clite.user.getPWData(uid);
|
|
},
|
|
endpwent:function() {},
|
|
getpwent:function() {
|
|
var e = clite.user.getPWDataInd(pwentind);
|
|
if (e !== null)
|
|
grentind++;
|
|
return e;
|
|
},
|
|
setpwent:function() {
|
|
pwentind = 0;
|
|
},
|
|
|
|
// returns the current group id
|
|
getgid:function() {
|
|
return clite.proc.getRGID(io.pid);
|
|
},
|
|
getegid:function() {
|
|
return clite.proc.getGID(io.pid);
|
|
},
|
|
setgid:function(gid) {
|
|
if (!clite.proc.setRGID(io.pid,gid,false))
|
|
return false;
|
|
return clite.proc.setGID(io.pid,gid,false);
|
|
},
|
|
setregid:function(rgid,egid) {
|
|
if (!clite.proc.setRGID(io.pid,rgid,false))
|
|
return false;
|
|
return clite.proc.setGID(io.pid,egid,false);
|
|
},
|
|
endgrent:function() {},
|
|
getgrent:function() {
|
|
var e = clite.user.getGRDataInd(grentind);
|
|
if (e !== null)
|
|
grentind++;
|
|
return e;
|
|
},
|
|
setgrent:function() {
|
|
grentind = 0;
|
|
},
|
|
|
|
// gets teh group file data for a group based on their gid
|
|
getgrgid:function(gid) {
|
|
return clite.user.getGRData(gid);
|
|
},
|
|
// gets teh group file data for a group based on their name
|
|
getgrnam:function(name) {
|
|
var gid = clite.user.mapGroupName(name);
|
|
if (gid < 0)
|
|
return null;
|
|
return clite.user.getGRData(gid);
|
|
},
|
|
|
|
// wait for any child process to exit
|
|
wait:function(cb) {
|
|
return clite.proc.addWaitGroupAny(io.pid,cb);
|
|
},
|
|
|
|
// wait for the process 'pid' to exit
|
|
waitpid:function(pid,cb) {
|
|
if (pid < 0)
|
|
return clite.proc.addWaitGroupAny(io.pid,cb);
|
|
return clite.proc.addWait(pid,cb);
|
|
},
|
|
|
|
// wait for all child processes to exit
|
|
waitall:function(cb) {
|
|
return clite.proc.addWaitGroupAll(io.pid,cb);
|
|
},
|
|
|
|
sleep:function(seconds,cb) {
|
|
return clite.core.execSafeAsync(function() {
|
|
cb(0);
|
|
},seconds*1000);
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|