Mercurial > hg > Members > kono > os9 > sbc09
changeset 148:fa0fbcbccbc9
add easy fmemopen replacement
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 17 Jan 2019 07:43:13 +0900 |
parents | 9d7faeeea618 |
children | 2f71506f980f |
files | src/vdisk.c |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/vdisk.c Sat Jan 12 15:20:00 2019 +0900 +++ b/src/vdisk.c Thu Jan 17 07:43:13 2019 +0900 @@ -256,6 +256,20 @@ return mode; } +#ifndef fmemopen + +FILE *fmemopen(char *buf,long sz, const char *mode) { + static char fname[] = "/tmp/myfileXXXXXX"; + int fd; + fd = mkstemp(fname); /* Create and open temp file */ + write(fd, buf, sz); /* Write something to file */ + lseek(fd, 0L, SEEK_SET); + FILE *fp = fdopen(fd,mode); + unlink(fname); + return fp; +} + +#endif /* * os9 file descriptor