19 #if POTION_WIN32 && !defined(__MINGW_SCANF_FORMAT)
20 int vasprintf (
char **strp,
const char *fmt, __VALIST ap);
21 int asprintf (
char **string_ptr,
const char *format, ...);
24 #if defined(__linux__) || defined(__CYGWIN__)
34 typedef vPN(BufFile) pn_ffile;
35 const
int BufFileSize = sizeof(struct
PNBufFile) - sizeof(struct
PNData);
48 self->
siz = BufFileSize;
60 self->
siz = BufFileSize;
61 self->file = tmpfile();
77 self->siz = BufFileSize;
98 self->siz = BufFileSize;
100 self->path = stream->path;
113 PN potion_buffile_fmemopen(
Potion *P,
PN cl,
PN buf,
PN modestr) {
119 self->
siz = BufFileSize;
130 return PN_NUM(fclose(self->file));
136 return PN_NUM(fgetc(self->file));
144 if (fgets(line, 1024, self->file) != NULL)
167 if (!size && (!nitems ||
PN_INT(nitems) == 1)) {
203 if (fflush(self->file))
222 long r = ftell(self->file);
231 int r = feof(self->file);
237 return PN_NUM(fileno(self->file));
243 if (fileno(self->file) != -1) fclose(self->file);
244 if (!self->path || unlink(
PN_STR_PTR(self->path))) {
253 flockfile(self->file);
return PN_TRUE;
259 return PN_NUM(ftrylockfile(self->file));
264 funlockfile(self->file);
return PN_TRUE;
272 PN potion_buffile_fprintf(
Potion *P,
PN cl, pn_ffile
self,
PN fmt, ...) {
279 int fd = fileno(self->file), rv;
282 if (self->path !=
PN_NIL && fd != -1) {
283 rv = asprintf(&buf,
"<buffile %s fd: %d>",
PN_STR_PTR(self->path), fd);
284 }
else if (fd != -1) {
285 rv = asprintf(&buf,
"<buffile %p fd: %d>", self->file, fd);
287 rv = asprintf(&buf,
"<closed buffile %p>", self->file);
PN potion_buffile_tmpfile(Potion *P, PN cl, PN ign)
PN potion_str(Potion *, const char *)
PN potion_buffile_freopen(Potion *P, PN cl, pn_ffile self, PN path, PN modestr, pn_ffile stream)
PN potion_buffile_ftell(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_fileno(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_fseek(Potion *P, PN cl, pn_ffile self, PN offset, PN whence)
struct to wrap arbitrary data that we may want to allocate from Potion.
PN PN potion_byte_str(Potion *, const char *)
#define potion_method(RCV, MSG, FN, SIG)
static struct PNData * potion_data_alloc(Potion *P, int siz)
PN potion_buffile_fflush(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_ftrylockfile(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_flockfile(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_fputc(Potion *P, PN cl, pn_ffile self, PN byte)
PN potion_io_error(Potion *P, const char *msg)
DLLEXPORT void Potion_Init_buffile(Potion *P)
PN potion_type_error(Potion *P, PN obj)
PN potion_buffile_fgets(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_fclose(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_unlink(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_fputs(Potion *P, PN cl, pn_ffile self, PN str)
PN potion_buffile_fgetc(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_fwrite(Potion *P, PN cl, pn_ffile self, PN buf, PN size, PN nitems)
PN potion_buffile_string(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_fread(Potion *P, PN cl, pn_ffile self, PN buf, PN size, PN nitems)
PN potion_buffile_fdopen(Potion *P, PN cl, pn_ffile self, PN fd, PN modestr)
the global interpreter state P. currently singleton (not threads yet)
#define potion_send(RCV, MSG, ARGS...)
method caches (more great stuff from ian piumarta)
PN potion_type_new2(Potion *P, PNType t, PN self, PN name)
create a named type
void potion_allocation_error(void)
void potion_type_constructor_is(PN vt, PN cl)
set default constructor
PN potion_buffile_feof(Potion *P, PN cl, pn_ffile self)
PN potion_buffile_funlockfile(Potion *P, PN cl, pn_ffile self)