about summary refs log tree commit homepage
path: root/lib/unicorn/util.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/unicorn/util.rb')
-rw-r--r--lib/unicorn/util.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/unicorn/util.rb b/lib/unicorn/util.rb
index 2d3f827..d2214b7 100644
--- a/lib/unicorn/util.rb
+++ b/lib/unicorn/util.rb
@@ -1,4 +1,5 @@
 require 'fcntl'
+require 'tmpdir'
 
 module Unicorn
   class Util
@@ -39,6 +40,22 @@ module Unicorn
         nr
       end
 
+      # creates and returns a new File object.  The File is unlinked
+      # immediately, switched to binary mode, and userspace output
+      # buffering is disabled
+      def tmpio
+        fp = begin
+          File.open("#{Dir::tmpdir}/#{rand}",
+                    File::RDWR|File::CREAT|File::EXCL, 0600)
+        rescue Errno::EEXIST
+          retry
+        end
+        File.unlink(fp.path)
+        fp.binmode
+        fp.sync = true
+        fp
+      end
+
     end
 
   end