Merge pull request #2945 from aidanhs/aphs-ungetc-nodefs-fixes

Fix ungetc on nodefs
This commit is contained in:
Alon Zakai 2014-10-30 15:06:51 -07:00
Родитель 265e6462d1 7710a3369b
Коммит 924f0d3c7a
5 изменённых файлов: 20 добавлений и 9 удалений

Просмотреть файл

@ -1068,7 +1068,9 @@ mergeInto(LibraryManager.library, {
if (!stream.seekable || !stream.stream_ops.llseek) {
throw new FS.ErrnoError(ERRNO_CODES.ESPIPE);
}
return stream.stream_ops.llseek(stream, offset, whence);
stream.position = stream.stream_ops.llseek(stream, offset, whence);
stream.ungotten = [];
return stream.position;
},
read: function(stream, buffer, offset, length, position) {
if (length < 0 || position < 0) {

Просмотреть файл

@ -335,8 +335,6 @@ mergeInto(LibraryManager.library, {
if (position < 0) {
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
}
stream.ungotten = [];
stream.position = position;
return position;
},
allocate: function(stream, offset, length) {

Просмотреть файл

@ -233,6 +233,7 @@ mergeInto(LibraryManager.library, {
}
},
read: function (stream, buffer, offset, length, position) {
if (length === 0) return 0; // node errors on 0 length reads
// FIXME this is terrible.
var nbuffer = new Buffer(length);
var res;
@ -278,7 +279,6 @@ mergeInto(LibraryManager.library, {
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);
}
stream.position = position;
return position;
}
}

Просмотреть файл

@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <emscripten.h>
static void create_file(const char *path, const char *buffer, int mode) {
int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, mode);
@ -17,11 +18,11 @@ static void create_file(const char *path, const char *buffer, int mode) {
}
void setup() {
create_file("file.txt", "cd", 0666);
create_file("/tmp/file.txt", "cd", 0666);
}
void cleanup() {
unlink("file.txt");
unlink("/tmp/file.txt");
}
void test() {
@ -29,7 +30,7 @@ void test() {
int err;
char buffer[256];
file = fopen("file.txt", "r");
file = fopen("/tmp/file.txt", "r");
assert(file);
// pushing EOF always returns EOF
@ -82,6 +83,11 @@ void test() {
}
int main() {
#ifdef NODEFS
EM_ASM(FS.mount(NODEFS, { root: '.' }, '/tmp'));
#elif MEMFS
EM_ASM(FS.mount(MEMFS, {}, '/tmp'));
#endif
atexit(cleanup);
signal(SIGABRT, cleanup);
setup();

Просмотреть файл

@ -4276,8 +4276,13 @@ def process(filename):
self.do_run_from_file(src, output)
def test_fgetc_ungetc(self):
src = open(path_from_root('tests', 'stdio', 'test_fgetc_ungetc.c'), 'r').read()
self.do_run(src, 'success', force_c=True)
self.clear()
if not self.is_emscripten_abi(): return self.skip('asmjs-unknown-emscripten needed for inline js')
orig_compiler_opts = Building.COMPILER_TEST_OPTS[:]
for fs in ['MEMFS', 'NODEFS']:
src = open(path_from_root('tests', 'stdio', 'test_fgetc_ungetc.c'), 'r').read()
Building.COMPILER_TEST_OPTS = orig_compiler_opts + ['-D' + fs]
self.do_run(src, 'success', force_c=True, js_engines=[NODE_JS])
def test_fgetc_unsigned(self):
if self.emcc_args is None: return self.skip('requires emcc')