Update to work with new libc headers.

This commit is contained in:
Bruce Mitchener 2013-08-23 15:11:49 +07:00 коммит произвёл Alon Zakai
Родитель 5c6e1633d2
Коммит a9d0a7f981
5 изменённых файлов: 107 добавлений и 61 удалений

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

@ -29,11 +29,11 @@ LibraryManager.library = {
// ==========================================================================
__dirent_struct_layout: Runtime.generateStructInfo([
['i32', 'd_ino'],
['b1024', 'd_name'],
['i32', 'd_off'],
['i32', 'd_reclen'],
['i32', 'd_type']]),
['i64', 'd_ino'],
['i64', 'd_off'],
['i16', 'd_reclen'],
['i8', 'd_type'],
['b256', 'd_name']]),
opendir__deps: ['$FS', '__setErrNo', '$ERRNO_CODES', '__dirent_struct_layout', 'open'],
opendir: function(dirname) {
// DIR *opendir(const char *dirname);
@ -82,7 +82,7 @@ LibraryManager.library = {
seekdir: function(dirp, loc) {
// void seekdir(DIR *dirp, long int loc);
// http://pubs.opengroup.org/onlinepubs/007908799/xsh/seekdir.html
_lseek(dirp, loc, {{{ cDefine('SEEK_SET') }}});
_lseek(dirp, loc, 0, {{{ cDefine('SEEK_SET') }}});
},
rewinddir__deps: ['seekdir'],
rewinddir: function(dirp) {
@ -254,23 +254,27 @@ LibraryManager.library = {
// ==========================================================================
__stat_struct_layout: Runtime.generateStructInfo([
['i32', 'st_dev'],
['i32', 'st_ino'],
['i64', 'st_dev'],
['i32', '__st_dev_padding'],
['i32', '__st_ino_truncated'],
['i32', 'st_mode'],
['i32', 'st_nlink'],
['i32', 'st_uid'],
['i32', 'st_gid'],
['i32', 'st_rdev'],
['i32', 'st_size'],
['i32', 'st_atime'],
['i32', 'st_spare1'],
['i32', 'st_mtime'],
['i32', 'st_spare2'],
['i32', 'st_ctime'],
['i32', 'st_spare3'],
['i64', 'st_rdev'],
['i32', '__st_rdev_padding'],
['i32', '__st_rdev_padding2'],
['i64', 'st_size'],
['i32', 'st_blksize'],
['i32', 'st_blocks'],
['i32', 'st_spare4']]),
['i32', '__st_blksize_padding'],
['i64', 'st_blocks'],
['i32', 'st_atim_secs'],
['i32', 'st_atim_nsecs'],
['i32', 'st_mtim_secs'],
['i32', 'st_mtim_nsecs'],
['i32', 'st_ctim_secs'],
['i32', 'st_ctim_nsecs'],
['i64', 'st_ino']]),
stat__deps: ['$FS', '__stat_struct_layout'],
stat: function(path, buf, dontResolveLastLink) {
// http://pubs.opengroup.org/onlinepubs/7908799/xsh/stat.html
@ -281,18 +285,26 @@ LibraryManager.library = {
try {
var stat = dontResolveLastLink ? FS.lstat(path) : FS.stat(path);
{{{ makeSetValue('buf', '___stat_struct_layout.st_dev', 'stat.dev', 'i32') }}};
{{{ makeSetValue('buf', '___stat_struct_layout.st_ino', 'stat.ino', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.__st_dev_padding', '0', 'i32') }}};
{{{ makeSetValue('buf', '___stat_struct_layout.__st_ino_truncated', 'stat.ino', 'i32') }}};
{{{ makeSetValue('buf', '___stat_struct_layout.st_mode', 'stat.mode', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_nlink', 'stat.nlink', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_uid', 'stat.uid', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_gid', 'stat.gid', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_rdev', 'stat.rdev', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.__st_rdev_padding', '0', 'i32') }}};
{{{ makeSetValue('buf', '___stat_struct_layout.__st_rdev_padding2', '0', 'i32') }}};
{{{ makeSetValue('buf', '___stat_struct_layout.st_size', 'stat.size', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_atime', 'Math.floor(stat.atime.getTime() / 1000)', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_mtime', 'Math.floor(stat.mtime.getTime() / 1000)', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_ctime', 'Math.floor(stat.ctime.getTime() / 1000)', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_blksize', '4096', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.__st_blksize_padding', '0', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_blocks', 'stat.blocks', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_atim_secs', 'Math.floor(stat.atime.getTime() / 1000)', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_atim_nsecs', '0', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_mtim_secs', 'Math.floor(stat.mtime.getTime() / 1000)', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_mtim_nsecs', '0', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_ctim_secs', 'Math.floor(stat.ctime.getTime() / 1000)', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_ctim_nsecs', '0', 'i32') }}}
{{{ makeSetValue('buf', '___stat_struct_layout.st_ino', 'stat.ino', 'i32') }}}
return 0;
} catch (e) {
FS.handleFSError(e);
@ -317,7 +329,7 @@ LibraryManager.library = {
return _stat(stream.path, buf);
},
mknod__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
mknod: function(path, mode, dev) {
mknod: function(path, mode, dev_lo, dev_hi) {
// int mknod(const char *path, mode_t mode, dev_t dev);
// http://pubs.opengroup.org/onlinepubs/7908799/xsh/mknod.html
path = Pointer_stringify(path);
@ -335,7 +347,7 @@ LibraryManager.library = {
return -1;
}
try {
FS.mknod(path, mode, dev);
FS.mknod(path, mode, dev_lo);
return 0;
} catch (e) {
FS.handleFSError(e);
@ -431,15 +443,22 @@ LibraryManager.library = {
__statvfs_struct_layout: Runtime.generateStructInfo([
['i32', 'f_bsize'],
['i32', 'f_frsize'],
['i32', 'f_blocks'],
['i32', 'f_bfree'],
['i32', 'f_bavail'],
['i32', 'f_files'],
['i32', 'f_ffree'],
['i32', 'f_favail'],
['i64', 'f_blocks'],
['i64', 'f_bfree'],
['i64', 'f_bavail'],
['i64', 'f_files'],
['i64', 'f_ffree'],
['i64', 'f_favail'],
['i32', 'f_fsid'],
['i32', '__padding'],
['i32', 'f_flag'],
['i32', 'f_namemax']]),
['i32', 'f_namemax'],
['i32', '__reserved_1'],
['i32', '__reserved_2'],
['i32', '__reserved_3'],
['i32', '__reserved_4'],
['i32', '__reserved_5'],
['i32', '__reserved_6']]),
statvfs__deps: ['$FS', '__statvfs_struct_layout'],
statvfs: function(path, buf) {
// http://pubs.opengroup.org/onlinepubs/009695399/functions/statvfs.html
@ -567,7 +586,7 @@ LibraryManager.library = {
// Should never be reached. Only to silence strict warnings.
return -1;
},
posix_fadvise: function(fd, offset, len, advice) {
posix_fadvise: function(fd, offset_lo, offset_hi, len_lo, len_hi, advice) {
// int posix_fadvise(int fd, off_t offset, off_t len, int advice);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
// Advise as much as you wish. We don't care.
@ -575,7 +594,7 @@ LibraryManager.library = {
},
posix_madvise: 'posix_fadvise',
posix_fallocate__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
posix_fallocate: function(fd, offset, len) {
posix_fallocate: function(fd, offset_lo, offset_hi, len_lo, len_hi) {
// int posix_fallocate(int fd, off_t offset, off_t len);
// http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_fallocate.html
var stream = FS.getStream(fd);
@ -584,7 +603,7 @@ LibraryManager.library = {
return -1;
}
try {
FS.allocate(stream, offset, len);
FS.allocate(stream, offset_lo, len_lo);
return 0;
} catch (e) {
FS.handleFSError(e);
@ -863,13 +882,13 @@ LibraryManager.library = {
},
fdatasync: 'fsync',
truncate__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
truncate: function(path, length) {
truncate: function(path, length_lo, length_hi) {
// int truncate(const char *path, off_t length);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/truncate.html
// NOTE: The path argument may be a string, to simplify ftruncate().
if (typeof path !== 'string') path = Pointer_stringify(path);
try {
FS.truncate(path, length);
FS.truncate(path, length_lo);
return 0;
} catch (e) {
FS.handleFSError(e);
@ -877,11 +896,11 @@ LibraryManager.library = {
}
},
ftruncate__deps: ['$FS', '__setErrNo', '$ERRNO_CODES', 'truncate'],
ftruncate: function(fildes, length) {
ftruncate: function(fildes, length_lo, length_hi) {
// int ftruncate(int fildes, off_t length);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/ftruncate.html
try {
FS.ftruncate(fildes, length);
FS.ftruncate(fildes, length_lo);
return 0;
} catch (e) {
FS.handleFSError(e);
@ -943,7 +962,7 @@ LibraryManager.library = {
return -1;
},
lockf__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
lockf: function(fildes, func, size) {
lockf: function(fildes, func, size_lo, size_hi) {
// int lockf(int fildes, int function, off_t size);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/lockf.html
var stream = FS.getStream(fildes);
@ -957,16 +976,17 @@ LibraryManager.library = {
}
},
lseek__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
lseek: function(fildes, offset, whence) {
lseek: function(fildes, offset_lo, offset_hi, whence) {
// off_t lseek(int fildes, off_t offset, int whence);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/lseek.html
var stream = FS.getStream(fildes);
tempRet0 = 0;
if (!stream) {
___setErrNo(ERRNO_CODES.EBADF);
return -1;
}
try {
return FS.llseek(stream, offset, whence);
return FS.llseek(stream, offset_lo, whence);
} catch (e) {
FS.handleFSError(e);
return -1;
@ -982,7 +1002,7 @@ LibraryManager.library = {
return -1;
},
pread__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
pread: function(fildes, buf, nbyte, offset) {
pread: function(fildes, buf, nbyte, offset_lo, offset_hi) {
// ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/read.html
var stream = FS.getStream(fildes);
@ -997,7 +1017,7 @@ LibraryManager.library = {
SAFE_HEAP_FILL_HISTORY(buf, buf+nbyte, 'i8'); // VFS does not use makeSetValues, so we need to do it manually
#endif
#endif
return FS.read(stream, slab, buf, nbyte, offset);
return FS.read(stream, slab, buf, nbyte, offset_lo);
} catch (e) {
FS.handleFSError(e);
return -1;
@ -1117,7 +1137,7 @@ LibraryManager.library = {
return str.length;
},
pwrite__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
pwrite: function(fildes, buf, nbyte, offset) {
pwrite: function(fildes, buf, nbyte, offset_lo, offset_hi) {
// ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/write.html
var stream = FS.getStream(fildes);
@ -1132,7 +1152,7 @@ LibraryManager.library = {
SAFE_HEAP_FILL_HISTORY(buf, buf+nbyte, 'i8'); // VFS does not use makeSetValues, so we need to do it manually
#endif
#endif
return FS.write(stream, slab, buf, nbyte, offset);
return FS.write(stream, slab, buf, nbyte, offset_lo);
} catch (e) {
FS.handleFSError(e);
return -1;
@ -2535,7 +2555,7 @@ LibraryManager.library = {
fseek: function(stream, offset, whence) {
// int fseek(FILE *stream, long offset, int whence);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/fseek.html
var ret = _lseek(stream, offset, whence);
var ret = _lseek(stream, offset, 0, whence);
if (ret == -1) {
return -1;
}
@ -2543,8 +2563,8 @@ LibraryManager.library = {
stream.eof = false;
return 0;
},
fseeko: 'fseek',
fseeko64: 'fseek',
fseeko: 'lseek',
fseeko64: 'lseek',
fsetpos__deps: ['$FS', 'lseek', '__setErrNo', '$ERRNO_CODES'],
fsetpos: function(stream, pos) {
// int fsetpos(FILE *stream, const fpos_t *pos);
@ -2580,8 +2600,15 @@ LibraryManager.library = {
return stream.position;
}
},
ftello: 'ftell',
ftello64: 'ftell',
ftello__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
ftello: function(stream) {
// off_t ftello(FILE *stream);
// http://pubs.opengroup.org/onlinepubs/000095399/functions/ftello.html
var result = ftell(stream);
tempRet0 = result << 32;
return 0;
},
ftello64: 'ftello',
fwrite__deps: ['$FS', 'write'],
fwrite: function(ptr, size, nitems, stream) {
// size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restrict stream);
@ -5023,11 +5050,12 @@ LibraryManager.library = {
// ==========================================================================
__utsname_struct_layout: Runtime.generateStructInfo([
['b32', 'sysname'],
['b32', 'nodename'],
['b32', 'release'],
['b32', 'version'],
['b32', 'machine']]),
['b65', 'sysname'],
['b65', 'nodename'],
['b65', 'release'],
['b65', 'version'],
['b65', 'machine'],
['b65', 'domainname']]),
uname__deps: ['__utsname_struct_layout'],
uname: function(name) {
// int uname(struct utsname *name);

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

@ -0,0 +1,18 @@
#ifndef _COMPAT_TIME_H
#define _COMPAT_TIME_H
#ifdef __cplusplus
extern "C" {
#endif
int dysize(int year);
#define _timezone timezone
#define _daylight daylight
#ifdef __cplusplus
}
#endif
#include_next <time.h>
#endif

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

@ -3,7 +3,7 @@ errno: 0
gethostname/2 ret: -1
gethostname/2: em------------------------
errno: 91
errno: 36
gethostname/256 ret: 0
gethostname/256: emscripten

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

@ -11,8 +11,8 @@ lockf(good): 0, errno: 0
lockf(bad): -1, errno: 9
nice: 0, errno: 1
pause: -1, errno: 4
pipe(good): -1, errno: 88
pipe(bad): -1, errno: 88
pipe(good): -1, errno: 38
pipe(bad): -1, errno: 38
execl: -1, errno: 8
execle: -1, errno: 8
execlp: -1, errno: 8
@ -29,8 +29,8 @@ alarm: 0, errno: 0
ualarm: 0, errno: 0
fork: -1, errno: 11
vfork: -1, errno: 11
crypt: (null), errno: 88
encrypt, errno: 88
crypt: (null), errno: 38
encrypt, errno: 38
getgid: 0, errno: 0
getegid: 0, errno: 0
getuid: 0, errno: 0

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

@ -1,4 +1,4 @@
zlib version 1.2.5 = 4688, compile flags = 85
zlib version 1.2.5 = 4688, compile flags = 149
uncompress(): hello, hello!
inflate(): hello, hello!
large_inflate(): OK