Skip to content

Commit

Permalink
Merge pull request JuliaLang#1176 from kmsquire/doc_updates
Browse files Browse the repository at this point in the history
Updated `cstring` to `bytestring` in manual.
  • Loading branch information
Keno committed Aug 18, 2012
2 parents 4f69289 + 4326b6e commit 856b3b6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/manual/calling-c-and-fortran-code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ of an environment variable, one makes a call like this:
julia> path = ccall(dlsym(libc, :getenv), Ptr{Uint8}, (Ptr{Uint8},), "SHELL")
Ptr{Uint8} @0x00007fff5fbfd670

julia> cstring(path)
julia> bytestring(path)
"/bin/zsh"

Note that the argument type tuple must be written as ``(Ptr{Uint8},)``,
Expand Down Expand Up @@ -111,11 +111,11 @@ in

function getenv(var::String)
val = ccall(dlsym(libc, :getenv),
Ptr{Uint8}, (Ptr{Uint8},), cstring(var))
Ptr{Uint8}, (Ptr{Uint8},), bytestring(var))
if val == C_NULL
error("getenv: undefined variable: ", var)
end
cstring(val)
bytestring(val)
end

The C ``getenv`` function indicates an error by returning ``NULL``, but
Expand All @@ -142,7 +142,7 @@ machine's hostname:
ccall(dlsym(libc, :gethostname), Int32,
(Ptr{Uint8}, Ulong),
hostname, length(hostname))
return cstring(convert(Ptr{Uint8}, hostname))
return bytestring(convert(Ptr{Uint8}, hostname))
end

This example first allocates an array of bytes, then calls the C library
Expand Down

0 comments on commit 856b3b6

Please sign in to comment.