--- /dev/null
+// extern FILE *fopen(char *path, char *mode);
+function psi\fopen(string $path, string $mode) : object {
+ let path = pathval($path);
+ let mode = strval($mode);
+ return to_object(*fopen);
+}
+
+// extern int fclose(FILE *stream);
+function psi\fclose(object $stream) : int {
+ let stream = objval($stream);
+ return to_int(fclose);
+}
+
+// extern size_t fread(void *buf, size_t len, size_t n, FILE *stream);
+function psi\fread(object $stream, string &$data = NULL, int $len = 1, int $n = 8192) : int {
+ let len = intval($len);
+ let n = intval($n);
+ let stream = objval($stream);
+ let buf = calloc(n, len);
+ return to_int(fread);
+ set $data = to_string(buf, fread * len);
+}
+
+// extern int feof(FILE *stream);
+function psi\feof(object $stream) : int {
+ let stream = objval($stream);
+ return to_int(feof);
+}
+
+// extern int fileno(FILE *stream);
+function psi\fileno(object $stream) : int {
+ let stream = objval($stream);
+ return to_int(fileno);
+}
+
+// extern int ferror(FILE *stream);
+function psi\ferror(object $stream) : int {
+ let stream = objval($stream);
+ return to_int(ferror);
+}
+
+// extern void clearerr(FILE *stream);
+function psi\clearerr(object $stream) : void {
+ let stream = objval($stream);
+ return void(clearerr);
+}
+
+// extern int fseek(FILE *stream, long offset, int whence);
+function psi\fseek(object $stream, int $offset, int $whence) : int {
+ let stream = objval($stream);
+ let offset = intval($offset);
+ let whence = intval($whence);
+ return to_int(fseek);
+}
+
+//extern long ftell(FILE *stream);
+function psi\ftell(object $stream) : int {
+ let stream = objval($stream);
+ return to_int(ftell);
+}
+
+// extern void rewind(FILE *stream);
+function psi\rewind(object $stream) : void {
+ let stream = objval($stream);
+ return void(rewind);
+}
PSI_MACROS
-size_t psi_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
-{
- size_t rv = fread(ptr, size, nmemb, stream);
+int psi_glob(const char *pattern, int flags,
+ int (*errfunc) (const char *epath, int eerrno),
+ glob_t *pglob) {
+ size_t offs = flags & GLOB_DOOFFS ? pglob->gl_offs : 0;
+ int rv = glob(pattern, flags, errfunc, pglob);
+ if (pglob->gl_pathv) {
+ while (offs--) {
+ pglob->gl_pathv[offs] = NULL;
+ }
+ }
return rv;
}
-FILE *psi_fopen(const char *path, const char *mode)
-{
- FILE *f = fopen(path, mode);
- return f;
-}
-
static struct psi_func_redir {
const char *name;
void (*func)(void);
} psi_func_redirs[] = {
- {"fopen", (void (*)(void)) psi_fopen},
- {"fread", (void (*)(void)) psi_fread},
+ {"glob", (void (*)(void)) psi_glob},
PSI_REDIRS
{0}
};