readlinkat syscall and readlink refactoring

This commit is contained in:
Alon Zakai 2015-06-01 13:25:40 -07:00
Родитель 03a712d2f6
Коммит ac78339e95
1 изменённых файлов: 16 добавлений и 5 удалений

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

@ -436,6 +436,13 @@ mergeInto(LibraryManager.library, {
FS.mknod(path, mode, dev);
return 0;
},
doReadlink: function(path, buf, bufsize) {
if (bufsize <= 0) return -ERRNO_CODES.EINVAL;
var ret = FS.readlink(path);
ret = ret.slice(0, Math.max(0, bufsize));
writeStringToMemory(ret, buf, true);
return ret.length;
},
},
__syscall__deps: ['$SYSCALLS', '$FS', '$ERRNO_CODES', '$PATH', '__setErrNo', '$PROCINFO',
@ -685,11 +692,7 @@ mergeInto(LibraryManager.library, {
}
case 85: { // readlink
var path = getStr(), buf = get(), bufsize = get();
if (bufsize <= 0) return -ERRNO_CODES.EINVAL;
var ret = FS.readlink(path);
ret = ret.slice(0, Math.max(0, bufsize));
writeStringToMemory(ret, buf, true);
return ret.length;
return SYSCALLS.doReadlink(path, buf, bufsize);
}
case 91: { // munmap
var addr = get(), len = get();
@ -1161,6 +1164,14 @@ mergeInto(LibraryManager.library, {
FS.symlink(target, linkpath);
return 0;
}
case 305: { // readlinkat
#if SYSCALL_DEBUG
Module.printErr('warning: untested syscall');
#endif
var dirfd = get(), path = getStr(), buf = get(), bufsize = get();
path = SYSCALLS.calculateAt(dirfd, path);
return SYSCALLS.doReadlink(path, buf, bufsize);
}
case 324: { // fallocate
var stream = getStreamFromFD(), mode = get(), offset = get64(), len = get64();
assert(mode === 0);