mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
101 lines
2.2 KiB
JavaScript
101 lines
2.2 KiB
JavaScript
clite.libs.data = function() {
|
|
|
|
clite.libs.load('libstd','stdlib',function(io,env) {
|
|
|
|
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('/');
|
|
},
|
|
|
|
// 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.getUID(io.pid);
|
|
},
|
|
|
|
// 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);
|
|
},
|
|
|
|
// returns the current group id
|
|
getgid:function() {
|
|
return clite.proc.getGID(io.pid);
|
|
},
|
|
|
|
// 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);
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|