sexp sexp_postmountsrv (sexp ctx, sexp self, sexp_sint_t n, sexp ls, sexp name, sexp mtpt, sexp flags) { Srv s; struct sexp_plan9_srv p9s; if (! sexp_listp(ctx, ls)) return sexp_type_exception(ctx, self, SEXP_PAIR, ls); if (! sexp_stringp(name)) return sexp_type_exception(ctx, self, SEXP_STRING, name); if (! sexp_stringp(mtpt)) return sexp_type_exception(ctx, self, SEXP_STRING, mtpt); if (! sexp_integerp(flags)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, flags); sexp_build_srv(ctx, &p9s, ls); s.aux = &p9s; s.auth = &sexp_9p_auth; s.attach = &sexp_9p_attach; s.walk = &sexp_9p_walk; s.walk1 = &sexp_9p_walk1; s.clone = &sexp_9p_clone; s.open = &sexp_9p_open; s.create = &sexp_9p_create; s.remove = &sexp_9p_remove; s.read = &sexp_9p_read; s.write = &sexp_9p_write; s.stat = &sexp_9p_stat; s.wstat = &sexp_9p_wstat; s.flush = &sexp_9p_flush; s.destroyfid = &sexp_9p_destroyfid; s.destroyreq = &sexp_9p_destroyreq; s.end = &sexp_9p_end; postmountsrv(&s, sexp_string_data(name), sexp_string_data(mtpt), sexp_unbox_fixnum(flags)); return SEXP_UNDEF; }
static sexp sexp_readlink_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0, sexp arg1, sexp arg2) { sexp res; if (! sexp_stringp(arg0)) return sexp_type_exception(ctx, self, SEXP_STRING, arg0); if (! sexp_stringp(arg1)) return sexp_type_exception(ctx, self, SEXP_STRING, arg1); if (! sexp_exact_integerp(arg2)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, arg2); res = sexp_make_integer(ctx, readlink(sexp_string_data(arg0), sexp_string_data(arg1), sexp_sint_value(arg2))); return res; }
static sexp sexp_link_file_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0, sexp arg1) { int err; sexp res; if (! sexp_stringp(arg0)) return sexp_type_exception(ctx, self, SEXP_STRING, arg0); if (! sexp_stringp(arg1)) return sexp_type_exception(ctx, self, SEXP_STRING, arg1); err = link(sexp_string_data(arg0), sexp_string_data(arg1)); if (err) { res = SEXP_FALSE; } else { res = SEXP_TRUE; } return res; }
sexp sexp_getenv (sexp ctx, sexp self, sexp_sint_t n, sexp name) { char *value; if (! sexp_stringp(name)) return sexp_type_exception(ctx, self, SEXP_STRING, name); value = getenv(sexp_string_data(name)); return ((! value) ? SEXP_FALSE : sexp_c_string(ctx, value, -1)); }
static void sexp_print_simple (sexp ctx, sexp x, sexp out, int depth) { int i; if ((!sexp_pointerp(x)) || sexp_symbolp(x) || sexp_stringp(x) || sexp_flonump(x) || sexp_bignump(x)) { sexp_write(ctx, x, out); } else if (depth <= 0) { goto print_name; } else if (sexp_synclop(x)) { sexp_write_string(ctx, "#<sc ", out); sexp_print_simple(ctx, sexp_synclo_expr(x), out, depth); sexp_write_string(ctx, ">", out); } else if (sexp_pairp(x)) { sexp_write_char(ctx, '(', out); sexp_print_simple(ctx, sexp_car(x), out, depth-1); sexp_write_string(ctx, " . ", out); sexp_print_simple(ctx, sexp_cdr(x), out, depth-1); sexp_write_char(ctx, ')', out); } else if (sexp_vectorp(x)) { sexp_write_string(ctx, "#(", out); for (i=0; i<SEXP_HEAP_VECTOR_DEPTH && i<(int)sexp_vector_length(x); i++) { if (i>0) sexp_write_char(ctx, ' ', out); sexp_print_simple(ctx, sexp_vector_ref(x, i), out, depth-1); } if (i<(int)sexp_vector_length(x)) sexp_write_string(ctx, " ...", out); sexp_write_char(ctx, ')', out); } else { print_name: sexp_write_string(ctx, "#<", out); sexp_write(ctx, sexp_object_type_name(ctx, x), out); sexp_write_string(ctx, ">", out); } }
static sexp sexp_opendir_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0) { sexp res; if (! sexp_stringp(arg0)) return sexp_type_exception(ctx, self, SEXP_STRING, arg0); res = sexp_make_cpointer(ctx, sexp_unbox_fixnum(sexp_opcode_return_type(self)), opendir(sexp_string_data(arg0)), SEXP_FALSE, 1); return res; }
sexp sexp_file_exists_p (sexp ctx, sexp self, sexp_sint_t n, sexp path) { int res; uchar statbuf[STATMAX]; if (! sexp_stringp(path)) return sexp_type_exception(ctx, self, SEXP_STRING, path); res = stat(sexp_string_data(path), statbuf, sizeof(statbuf)); return (res < 0) ? SEXP_FALSE : SEXP_TRUE; }
sexp sexp_postnote (sexp ctx, sexp self, sexp_sint_t n, sexp pid, sexp note) { if (! sexp_integerp(pid)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, pid); if (! sexp_stringp(note)) return sexp_type_exception(ctx, self, SEXP_STRING, note); postnote(PNPROC, sexp_unbox_fixnum(pid), sexp_string_data(note)); return SEXP_VOID; }
static sexp sexp_random_source_state_set (sexp ctx, sexp self, sexp_sint_t n, sexp rs, sexp state) { if (! sexp_random_source_p(rs)) return sexp_type_exception(ctx, self, rs_type_id, rs); else if (! (sexp_stringp(state) && (sexp_string_size(state) == SEXP_RANDOM_STATE_SIZE))) return sexp_type_exception(ctx, self, SEXP_STRING, state); sexp_random_state(rs) = state; sexp_random_init(rs, 1); return SEXP_VOID; }
static sexp sexp_open_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0, sexp arg1, sexp arg2) { sexp res; if (! sexp_stringp(arg0)) return sexp_type_exception(ctx, self, SEXP_STRING, arg0); if (! sexp_exact_integerp(arg1)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, arg1); if (! sexp_exact_integerp(arg2)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, arg2); res = sexp_make_fileno(ctx, sexp_make_fixnum(open(sexp_string_data(arg0), sexp_sint_value(arg1), sexp_sint_value(arg2))), SEXP_FALSE); return res; }
static sexp sexp_change_directory_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0) { int err; sexp res; if (! sexp_stringp(arg0)) return sexp_type_exception(ctx, self, SEXP_STRING, arg0); err = chdir(sexp_string_data(arg0)); if (err) { res = SEXP_FALSE; } else { res = SEXP_TRUE; } return res; }
static sexp sexp_create_directory_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0, sexp arg1) { int err; sexp res; if (! sexp_stringp(arg0)) return sexp_type_exception(ctx, self, SEXP_STRING, arg0); if (! sexp_exact_integerp(arg1)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, arg1); err = mkdir(sexp_string_data(arg0), sexp_sint_value(arg1)); if (err) { res = SEXP_FALSE; } else { res = SEXP_TRUE; } return res; }
char* sexp_9p_clone (Fid *oldfid, Fid *newfid) { sexp_plan9_srv s = (sexp_plan9_srv)oldfid->pool->srv->aux; sexp res, ctx = s->context; sexp_gc_var(ptr, s_ptr); sexp_gc_var(args, s_args); sexp_gc_preserve(ctx, ptr, s_ptr); sexp_gc_preserve(ctx, args, s_args); ptr = sexp_make_cpointer(ctx, SEXP_CPOINTER, oldfid, SEXP_FALSE, 0); args = sexp_cons(ctx, ptr, SEXP_NULL); ptr = sexp_make_cpointer(ctx, SEXP_CPOINTER, newfid, SEXP_FALSE, 0); args = sexp_cons(ctx, ptr, args); res = sexp_apply(ctx, s->clone, args); sexp_gc_release(ctx, ptr, s_ptr); return sexp_stringp(res) ? sexp_string_data(res) : nil; }
sexp sexp_fdopen (sexp ctx, sexp self, sexp_sint_t n, sexp fd, sexp mode) { FILE *f; if (! sexp_integerp(fd)) return sexp_type_exception(ctx, self, SEXP_FIXNUM, fd); if (! sexp_stringp(mode)) return sexp_type_exception(ctx, self, SEXP_STRING, mode); f = fdopen(sexp_unbox_fixnum(fd), sexp_string_data(mode)); if (! f) return sexp_user_exception(ctx, SEXP_FALSE, "fdopen failed", fd); /* maybe use fd2path to get the name of the fd */ if (sexp_string_data(mode)[0] == 'w') return sexp_make_output_port(ctx, f, SEXP_FALSE); else return sexp_make_input_port(ctx, f, SEXP_FALSE); }
char* sexp_9p_walk1 (Fid *fid, char *name, Qid *qid) { sexp_plan9_srv s = (sexp_plan9_srv)fid->pool->srv->aux; sexp res, ctx = s->context; sexp_gc_var(ptr, s_ptr); sexp_gc_var(args, s_args); sexp_gc_preserve(ctx, ptr, s_ptr); sexp_gc_preserve(ctx, args, s_args); ptr = sexp_make_cpointer(ctx, SEXP_CPOINTER, qid, SEXP_FALSE, 0); args = sexp_cons(ctx, ptr, SEXP_NULL); ptr = sexp_c_string(ctx, name, -1); args = sexp_cons(ctx, ptr, args); ptr = sexp_make_cpointer(ctx, SEXP_CPOINTER, fid, SEXP_FALSE, 0); args = sexp_cons(ctx, ptr, args); res = sexp_apply(ctx, s->walk1, args); sexp_gc_release(ctx, ptr, s_ptr); return sexp_stringp(res) ? sexp_string_data(res) : nil; }
static sexp sexp_stat_stub (sexp ctx, sexp self, sexp_sint_t n, sexp arg0) { int err; struct stat* tmp1; sexp res; sexp_gc_var1(res1); if (! sexp_stringp(arg0)) return sexp_type_exception(ctx, self, SEXP_STRING, arg0); sexp_gc_preserve1(ctx, res1); tmp1 = (struct stat*) calloc(1, 1 + sizeof(tmp1[0])); err = stat(sexp_string_data(arg0), tmp1); if (err) { res = SEXP_FALSE; } else { res1 = sexp_make_cpointer(ctx, sexp_unbox_fixnum(sexp_opcode_arg2_type(self)), tmp1, SEXP_FALSE, 1); res = res1; } sexp_gc_release1(ctx); return res; }
sexp sexp_chdir (sexp ctx, sexp self, sexp_sint_t n, sexp path) { if (! sexp_stringp(path)) return sexp_type_exception(ctx, self, SEXP_STRING, path); chdir(sexp_string_data(path)); return SEXP_VOID; }
void sexp_exits (sexp ctx, sexp self, sexp_sint_t n, sexp msg) { exits(sexp_string_data(sexp_stringp(msg) ? msg : sexp_write_to_string(ctx, msg))); }
sexp sexp_9p_respond (sexp ctx, sexp self, sexp_sint_t n, sexp req, sexp err) { char *cerr = sexp_stringp(err) ? sexp_string_data(err) : nil; respond(sexp_cpointer_value(req), cerr); return SEXP_VOID; }