Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
unix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rinat Striungis
unix
Commits
15226db1
Commit
15226db1
authored
13 years ago
by
deian
Committed by
dterei
13 years ago
Browse files
Options
Downloads
Patches
Plain Diff
mkstemps
parent
28a7a416
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
System/Posix/Temp.hsc
+22
-1
22 additions, 1 deletion
System/Posix/Temp.hsc
System/Posix/Temp/ByteString.hsc
+22
-1
22 additions, 1 deletion
System/Posix/Temp/ByteString.hsc
cbits/HsUnix.c
+3
-0
3 additions, 0 deletions
cbits/HsUnix.c
include/HsUnix.h
+1
-0
1 addition, 0 deletions
include/HsUnix.h
with
48 additions
and
2 deletions
System/Posix/Temp.hsc
+
22
−
1
View file @
15226db1
...
...
@@ -17,7 +17,7 @@
-----------------------------------------------------------------------------
module System.Posix.Temp (
mkstemp, mkdtemp
mkstemp,
mkstemps,
mkdtemp
) where
#include "HsUnix.h"
...
...
@@ -69,6 +69,27 @@ mkstemp template' = do
return (name, h)
#endif
#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
-- |'mkstemps' - make a unique filename with a given prefix and suffix
-- and open it for reading\/writing (only safe on GHC & Hugs).
-- The returned 'FilePath' is the (possibly relative) path of
-- the created file, which contains 6 random characters in between
-- the prefix and suffix.
mkstemps :: String -> String -> IO (FilePath, Handle)
mkstemps prefix suffix = do
let template = prefix ++ "XXXXXX" ++ suffix
lenOfsuf :: CInt
lenOfsuf = fromIntegral $ length suffix
withFilePath template $ \ ptr -> do
fd <- throwErrnoIfMinus1 "mkstemps" (c_mkstemps ptr lenOfsuf)
name <- peekFilePath ptr
h <- fdToHandle (Fd fd)
return (name, h)
foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"
c_mkstemps :: CString -> CInt -> IO CInt
#endif
-- | Make a unique directory. The returned 'FilePath' is the path of the
-- created directory, which is padded with 6 random characters. The argument is
-- the desired prefix of the filepath of the temporary directory to be created.
...
...
This diff is collapsed.
Click to expand it.
System/Posix/Temp/ByteString.hsc
+
22
−
1
View file @
15226db1
...
...
@@ -17,7 +17,7 @@
-----------------------------------------------------------------------------
module System.Posix.Temp.ByteString (
mkstemp, mkdtemp
mkstemp,
mkstemps,
mkdtemp
) where
#include "HsUnix.h"
...
...
@@ -60,6 +60,27 @@ mkstemp template' = do
return (name, h)
#endif
#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)
-- |'mkstemps' - make a unique filename with a given prefix and suffix
-- and open it for reading\/writing (only safe on GHC & Hugs).
-- The returned 'RawFilePath' is the (possibly relative) path of
-- the created file, which contains 6 random characters in between
-- the prefix and suffix.
mkstemps :: ByteString -> ByteString -> IO (RawFilePath, Handle)
mkstemps prefix suffix = do
let template = prefix `B.append` (BC.pack "XXXXXX") `B.append` suffix
lenOfsuf :: CInt
lenOfsuf = fromIntegral $ B.length suffix
withFilePath template $ \ ptr -> do
fd <- throwErrnoIfMinus1 "mkstemps" (c_mkstemps ptr lenOfsuf)
name <- peekFilePath ptr
h <- fdToHandle (Fd fd)
return (name, h)
foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"
c_mkstemps :: CString -> CInt -> IO CInt
#endif
-- | Make a unique directory. The returned 'RawFilePath' is the path of the
-- created directory, which is padded with 6 random characters. The argument is
-- the desired prefix of the filepath of the temporary directory to be created.
...
...
This diff is collapsed.
Click to expand it.
cbits/HsUnix.c
+
3
−
0
View file @
15226db1
...
...
@@ -135,6 +135,9 @@ int __hscore_mkstemp(char *filetemplate) {
char
*
__hscore_mkdtemp
(
char
*
filetemplate
)
{
return
(
mkdtemp
(
filetemplate
));
}
int
__hscore_mkstemps
(
char
*
filetemplate
,
int
suffixlen
)
{
return
(
mkstemps
(
filetemplate
,
suffixlen
));
}
#endif
#if !defined(__MINGW32__) && !defined(irix_HOST_OS)
...
...
This diff is collapsed.
Click to expand it.
include/HsUnix.h
+
1
−
0
View file @
15226db1
...
...
@@ -175,6 +175,7 @@ int __hsunix_push_module(int fd, const char *module);
#if !defined(__MINGW32__)
int
__hscore_mkstemp
(
char
*
filetemplate
);
int
__hscore_mkstemps
(
char
*
filetemplate
,
int
suffixlen
);
char
*
__hscore_mkdtemp
(
char
*
filetemplate
);
#endif
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment