Skip to content

Commit

Permalink
Add jl_ftruncate wrapper
Browse files Browse the repository at this point in the history
Fix handle ABI compatibility issue on 32bits linux with `_FILE_OFFSET_BITS=64`.
  • Loading branch information
yuyichao committed Jan 6, 2016
1 parent 72ba6b6 commit ffeb91b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion base/mmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function grow!(io::IO, offset::Integer, len::Integer)
pos = position(io)
filelen = filesize(io)
if filelen < offset + len
failure = ccall(:ftruncate, Cint, (Cint, Coff_t), fd(io), offset+len)
failure = ccall(:jl_ftruncate, Cint, (Cint, Coff_t), fd(io), offset+len)
Base.systemerror(:ftruncate, failure != 0)
end
seek(io, pos)
Expand Down
2 changes: 1 addition & 1 deletion base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ function _shm_mmap_array(T, dims, shm_seg_name, mode)
# On OSX, ftruncate must to used to set size of segment, just lseek does not work.
# and only at creation time
if (mode & JL_O_CREAT) == JL_O_CREAT
rc = ccall(:ftruncate, Cint, (Cint, Coff_t), fd_mem, prod(dims)*sizeof(T))
rc = ccall(:jl_ftruncate, Cint, (Cint, Coff_t), fd_mem, prod(dims)*sizeof(T))
systemerror("ftruncate() failed for shm segment " * shm_seg_name, rc != 0)
end

Expand Down
2 changes: 1 addition & 1 deletion doc/stdlib/c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@

.. data:: Coff_t

Equivalent to the native ``off_t`` c-type
Equivalent to the native ``off_t`` c-type. Note that julia defines ``_FILE_OFFSET_BITS=64`` so this may not be the same as the default value on 32bits Linux.

.. data:: Cwchar_t

Expand Down
9 changes: 8 additions & 1 deletion src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ JL_DLLEXPORT int jl_sizeof_uv_mutex(void) { return sizeof(uv_mutex_t); }
JL_DLLEXPORT int jl_sizeof_off_t(void) { return sizeof(off_t); }
#ifndef _OS_WINDOWS_
JL_DLLEXPORT int jl_sizeof_mode_t(void) { return sizeof(mode_t); }
JL_DLLEXPORT off_t jl_lseek(int fd, off_t offset, int whence) { return lseek(fd, offset, whence); }
JL_DLLEXPORT int jl_ftruncate(int fd, off_t length)
{
return ftruncate(fd, length);
}
JL_DLLEXPORT off_t jl_lseek(int fd, off_t offset, int whence)
{
return lseek(fd, offset, whence);
}
JL_DLLEXPORT ssize_t jl_pwrite(int fd, const void *buf, size_t count, off_t offset)
{
return pwrite(fd, buf, count, offset);
Expand Down

0 comments on commit ffeb91b

Please sign in to comment.