Skip to content

Commit

Permalink
Moving unix-only tmp functions into a single block
Browse files Browse the repository at this point in the history
  • Loading branch information
Pontus Stenetorp committed Nov 18, 2014
1 parent 6537afe commit 9bd87c6
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ function touch(path::AbstractString)
end
end

@unix_only begin
# Obtain a temporary filename.
@unix_only function tempname()
function tempname()
d = get(ENV, "TMPDIR", C_NULL) # tempnam ignores TMPDIR on darwin
p = ccall(:tempnam, Ptr{UInt8}, (Ptr{UInt8},Ptr{UInt8}), d, "julia")
systemerror(:tempnam, p == C_NULL)
Expand All @@ -95,15 +96,23 @@ end
end

# Obtain a temporary directory's path.
@unix_only tempdir() = dirname(tempname())
tempdir() = dirname(tempname())

# Create and return the name of a temporary file along with an IOStream
@unix_only function mktemp()
function mktemp()
b = joinpath(tempdir(), "tmpXXXXXX")
p = ccall(:mkstemp, Int32, (Ptr{UInt8}, ), b) # modifies b
return (b, fdio(p, true))
end

# Create and return the name of a temporary directory
function mktempdir()
b = joinpath(tempdir(), "tmpXXXXXX")
p = ccall(:mkdtemp, Ptr{UInt8}, (Ptr{UInt8}, ), b)
return bytestring(p)
end
end

@windows_only begin
function tempdir()
temppath = Array(UInt16,32767)
Expand All @@ -130,16 +139,7 @@ function mktemp()
filename = tempname()
return (filename, open(filename,"r+"))
end
end

# Create and return the name of a temporary directory
@unix_only function mktempdir()
b = joinpath(tempdir(), "tmpXXXXXX")
p = ccall(:mkdtemp, Ptr{UInt8}, (Ptr{UInt8}, ), b)
return bytestring(p)
end

@windows_only function mktempdir()
function mktempdir()
seed::UInt32 = rand(UInt32)
dir = tempdir()
while true
Expand All @@ -155,6 +155,7 @@ end
seed += 1
end
end
end

function readdir(path::AbstractString)
# Allocate space for uv_fs_t struct
Expand Down

0 comments on commit 9bd87c6

Please sign in to comment.