This page continues SD Basic - System and Environment.
STATUS() and OS.ERROR()#
status() carries the result of the last operation that sets one. It is
overwritten constantly, so read it into a variable on the line after the call
you care about, not three lines later. Every status() value quoted in this
document set was captured that way.
os.error() carries the operating system's own error number from the last call
that made one, and is 0 when nothing has failed.
Codes worth knowing:
1004 |
item not found |
1006 |
bad action key |
1008 |
action failed — os.error() has the detail |
1011 |
timeout |
3001 |
subfile not found |
3006 |
record not found |
3007 |
no VOC record — from a failed open of a name that is not in the VOC |
3021 |
cannot gain exclusive access to a file |
3023 |
write or delete with no lock held |
7005 / 7012 / 7013 |
socket: cannot connect / cannot bind / closed |
CHECKSUM()#
checksum(string)
checksum('ABC') |
451 |
checksum('abc') |
291 |
checksum('ACB') |
448 |
checksum('') |
0 |
checksum('A' : @fm : 'B') |
-325 |
It is case sensitive and order sensitive, and it can be negative, so a program that stores it needs a signed field. It is a change detector, not a digest: it is short, and it is not a security primitive.
SDENCRYPT() and SDDECRYPT()#
sdencrypt(data, key, encoding)
sddecrypt(data, key, encoding)
Three arguments. The encoding is 201 for hex or 202 for base64.
A passphrase is not a key, but an ordinary program can make one.
sdencrypt('The quick brown fox', 'secretkey', 202) returns nothing and
sets status() to 10204, a key length error. The key has to
be an encoded 256-bit key. Make it with sdkey(passphrase, salt), where the salt
comes from sdsalt() and is kept with the data, or take a random one from
sdrandkey(); both are in every account. SD does not keep the key: a lost
passphrase is lost data. The three functions, the XE conversion that shows
an encrypted field decrypted, the key ring and the encrypt.key verb are on
SD Basic - Encrypting Data, with the worked example.
UMASK()#
umask(n)
Sets the file creation mask and returns the previous value. A negative argument asks without setting:
| call | returned | mask afterwards |
|---|---|---|
umask(-1) |
2 |
2 — unchanged |
umask(18) |
2 — the old value |
18 |
umask(-1) |
18 |
18 |
umask(2) |
18 |
2 — restored |
So the way to change it temporarily is to keep what the setting call returned and pass it back.
@SENTENCE and the other @variables#
@sentence holds the command line that started the program: RUN BP ZZMATH.
| Value | |
|---|---|
@who |
sduser — always, on an SD Core Solo for Linux computer |
@logname |
sduser |
@path |
/home/you/SDCoreSolo/user_accounts/sduser |
@sdsys |
/home/you/SDCoreSolo — the installation directory itself |
@userno |
67, the same as system(18) |
@tty |
empty in a piped session |
@system.return.code |
1 |
@user.return.code |
0 |
@crtwide / @crthigh |
200 / 9999 — whatever TERM last set |
@who and @logname are the same, sduser, and both are lower case. A
program that compares one with an upper-case literal fails; compare with
'sduser'.
set.exit.status sets what SD returns to the operating system when the session
ends.
OS.EXECUTE#
os.execute command {capturing variable | silent}
capturing puts the command's output in the variable; silent throws it
away, so nothing of it reaches the terminal.
It needs the os switch, which is off as delivered: a program that runs
OS.EXECUTE without it stops with sduser is not permitted to use OS.EXECUTE.
The administrator turns the switch on with set.os.access os on; a change is seen
at the next sign-on. Once it is on, OS.EXECUTE executes at the account's own
Linux permissions, the same wall that already governs what that account's user
could do at a shell prompt outside SD — see Operating system access in the
GettingStarted set. (OS.EXECUTE is not
subject to the metacharacter filter that the sh verb applies to a typed
command.)
LOGMSG#
logmsg text
Writes a line to SD's error log. It has no return value, and what status()
says afterwards is whatever the previous statement left there — worth knowing
because it looks like a result.
What is not here#
A whole family of functions is internal-only, and the compiler's complaint names something else entirely. This program, in an ordinary account:
v1 = kernel(28, 0)
v5 = option('X')
v6 = pterm(1, '')
compiles to, at the last line of the program (line 4 of this four-line
file, counting its end):
4: Matrix KERNEL is not referenced in a DIM statement
WARNING: KERNEL is not assigned a value
WARNING: OPTION is not assigned a value
WARNING: PTERM is not assigned a value
1 error(s)
A name the compiler does not know as a function is read as a matrix
reference, so the complaint is about a dim statement you never wrote, at a line
number nowhere near the call. If a function you are sure exists produces
that, it exists and this account may not call it. A call with three arguments
gives a different but equally misleading answer — sdext(101, 'pw', 'salt')
is "Right bracket not found where expected", because a matrix takes at most
two subscripts.
Internal-only: kernel(), option(), pterm(), sdext(), testlock() and
getlocks().
The compiler's list is longer than that; those six are the ones this page
put in front of it. They are reachable only from a program compiled
with $internal, which the compiler allows only in the installer's own
internal session.
ospath() is not on that list any more. Any program may call it, with the
openQM keys, and the OS access switch (set.os.access os on) decides what it may
look at:
ospath(path, key {, qualifier})
| key | name | answer |
|---|---|---|
| 0 · 1 | is path a valid path name · a valid single file name (text only, no gate) | |
| 2 | it exists, as a file or a directory | |
| 3 | a file name D and seven digits that is not in the directory path (the name, not the path) |
|
| 4 · 9 | os$fullpathx |
the full path name; SD keeps the case, so the two are one |
| 5 | delete a file or an empty directory — never a tree. True if it was removed | |
| 6 | is it open in SD, by any user | |
| 7 | when it was modified, as an epoch value; 0 if it is not there | |
| 8 | flush this process's cache of dynamic files; true | |
| 10 | os$parent |
the parent directory |
| 11 · 12 | os$uid · os$gid |
the owner's and group's numbers; 0 if the path is not there |
| 13 · 14 | make a directory · make it and the levels above it; true if done | |
| 15 | os$modes |
the permission bits as a decimal number (0755 is 493); 0 if it is not there |
| 16 · 17 | os$is.file · os$is.dir |
a file · a directory |
| 18 | the Windows owner: a null string on Linux |
The names are in the keys.h header; 6 and 18 have none, so give those as numbers. Every key that
looks at or changes the file system (all but 0, 1, 4, 8, 9, 10 and 18) asks the OS access switch
first: an account without it is held to its own directory, and a refusal
answers false with status() set to a permission error. Deleting or making a directory
whose path runs through the VOC is refused as a change of the VOC is, unless the session is the
administrator's or the OS switch is on. An unknown key answers false with
status() 1. The qualifier is read and ignored. An internal program's own ospath(), with its
different numbers, is unchanged.
And some statements are restricted the same way. These 34 are
"Unrecognized statement" to a program that is not compiled $internal by an
administrator:
add, akclear, akdelete, akenable, akread, akrelease, akwrite,
callv, configure.file, create.ak, delete.ak, delete.common,
keyboard.input, modify, quit, release.lock, remove.token,
reset.modes, rewind, run, set.modes, set.status, set.trigger,
set.unassigned, sortinit, unload.object, varset, writepkt, como,
and the whole debugging family — debug.on, debug.off, debug.set,
breakpoint and watch. SD Basic - Restricted Commands
carries the same names.
errmsg is not a statement at all. It compiles to "Unrecognized
statement" for everybody, as any word the compiler does not know does. It is not in the
compiler's statement table.
sendmail, chgphant() and ccall() compile for an ordinary account, and
each needs something outside SD before it can do anything: sendmail a mail
relay, chgphant a phantom to change, and ccall a C function registered into
the executable. Nothing on this page depends on them. sendmail takes its
else when the mail command cannot be run or ends with a failure: status()
is then 3010 (an I/O error) and os.error() holds the command's status.
See also#
SD Basic - Program Control · SD Basic - Data Conversion · SD Basic - Debugging · SD Basic - Locks and Transactions.